简体   繁体   English

TableviewCell中的图像

[英]Image in TableviewCell

I want to create TableViewCell with image. 我想用图像创建TableViewCell Image values from my plist. 来自我的列表的图像值。 Which method needed? 需要哪种方法? How do it? 怎么了 It is code by which i want to add image in tableviewcell 这是我想在tableviewcell添加图像的代码

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

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

My 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>

But it crashed 但它崩溃了

Since recently started to learn Objective-C . 从最近开始学习Objective-C can anyone help me out here? 有人可以帮我从这里出去吗?

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;

}

use this code 使用此代码

NSDictionary *picturesDictionary = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"my" ofType:@"plist"]]; NSDictionary * picturesDictionary = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@“ my” ofType:@“ plist”]] ;;

NSArray *imagesArray= [picturesDictionary allValues];

in table view methods use this 在表视图方法中使用此

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

You can add your own cell (New File --> Cocoa class with xib which is subclass to UITableViewCell). 您可以添加自己的单元格(带有xib的New File-> Cocoa类,它是UITableViewCell的子类)。 There you can add whatyou want and where you want (Image View, more Labels) 您可以在其中添加所需内容和所需位置(图像视图,更多标签)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM