我想創建帶有圖像的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