2016-04-26 12 views
0

TableViewCellイメージを作成します。私のplistからの画像値。どちらの方法が必要ですか?それはどうですか? それは私がtableviewcellImage in TableviewCell

NSArray *brend =[brends objectAtIndex:indexPath.row]; 
    NSString *logo = [[brend objectAtIndex:indexPath.row]valueForKey:@"Image"]; 

    cell.imageView.image=[UIImage imageNamed:logo]; 

私のplistに画像を追加することにより、コードです:

<dict> 
    <key>Mercedec</key> 
    <dict> 
     <key>Image</key> 
     <string>Mercedes.png</string> 
    </dict> 
    <key>Rena</key> 
    <dict> 
     <key>Image</key> 
     <string>Renault.png</string> 
    </dict> 

しかし、それは最近Objective-Cを学び始めたので

を墜落しました。誰か助けてくれますか?

EDIT:

@interface MainTableViewController() 
@property (nonatomic, copy) NSDictionary *companylist; 
@property (nonatomic, copy) NSArray *brends; 

@end 

@implementation MainTableViewController 

@synthesize brends,companylist; 

- (void)viewDidLoad { 
    [super viewDidLoad]; 


    UITableView *tableView = (id)[self.view viewWithTag:1]; 

    [tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell"]; 

    NSString *Stplist= [[NSBundle mainBundle] pathForResource:@"wunder" ofType:@"plist"]; 


    companylist = [[NSDictionary alloc]initWithContentsOfFile:Stplist]; 
    self.brends = [[self.companylist allKeys] sortedArrayUsingSelector:@selector(compare:)]; 

} 

#pragma mark - Table view data source 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 

    return 1; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 

    return brends.count; 
} 


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 


    static NSString *CellIdentifier = @"Cell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; 

    cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton; 

    cell.textLabel.text=brends[indexPath.row]; 


    NSArray *imagesArray= [companylist allValues ]; 


    NSString *logo= [[imagesArray objectAtIndex:indexPath.row]valueForKey:@"Image"]; 

    cell.imageView.image=[UIImage imageNamed:logo]; 


    return cell; 

} 
+0

は、クラッシュログを投稿できますか?ブレンドは何ですか?あなたのplistに基づいてそれが辞書であると考えられている配列か辞書ですか? – Joshua

+0

私はbrendが 'ブランド'だと思います - ブランドの車のように。 – headbanger

+0

この画像はJsonから入手できますか?実際にPlistに保存したいのですか? – Arun

答えて

1

使用このコード

NSDictionaryの* picturesDictionary = [NSDictionaryのdictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource: "私の" ofType @: "plistの" @]];

NSArray *imagesArray= [picturesDictionary allValues]; 

テーブルビューの方法は、この

NSString *yourPicName= [[imagesArray objectAtIndex:index.row]valueForKey:@"Image"]; 
+0

これは動作していますが、表示されている順序ではありません –

+0

NSDictionaryは並べ替えられていないコレクションです。 「私が追加した注文」とは意味がありません。 特定の順序でキーにアクセスするには、辞書の横に配列を格納するか、キーを取得して並べ替えて、その順序で値にアクセスする必要があります。 –

+0

たとえば? 正しく配置された画像のみ –

0

を使用して独自のセル(新規ファイル - のUITableViewCellにサブクラスであるXIBと>ココアクラス)を追加することができます。そこにあなたが望むものを追加することができます(画像の表示、より多くのラベル)

+0

私は別のセルは必要ありません。問題は、私はplistから画像データを取ることができないということです –