我想创建带有图像的TableViewCell
。来自我plist的图像值。需要哪种方法?它怎么样? 这是我想在tableviewcell
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
。有人可以帮我从这里出去吗?
编辑:
@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;
}
可以发布崩溃日志?什么是brends?这是一个基于你的plist的数组或字典,它应该是一本字典 – Joshua
我猜Brend是'品牌' - 就像汽车品牌一样。 – headbanger
您从Json获得此图片吗?您是否真的想将其存储在Plist中? – Arun