我正在尝试将数组中的三个不同图像加载到UITable中的相应单元格中。到目前为止,我有以下代码在运行t时构建精细崩溃。我可以帮助我,我会非常感激。
- (void)viewDidLoad {
NSArray *array = [[NSArray alloc] initWithObjects:@"Icon Nightclub", @"Smyhts Bar",
@"Synotts",nil];
self.listData = array;
NSArray *picArray = [[NSArray alloc] initWithObjects:@"ArrowLeftDefault.png", @"ArrowRightDefault.png",
@"events.png",nil];
self.picData = picArray;
[array release];
[picArray release];
[super viewDidLoad];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [listData count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SimpleTableIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:SimpleTableIdentifier] autorelease];
}
NSUInteger row = [indexPath row];
cell.textColor = [UIColor grayColor];
cell.textLabel.text = [listData objectAtIndex:row];
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
cell.imageView.image = [picData objectAtIndex:indexPath.row];
return cell;
}
答案 0 :(得分:4)
变化:
cell.imageView.image = [picData objectAtIndex:indexPath.row];
这样的事情:
cell.imageView.image = [UIImage imageNamed:[picData objectAtIndex:indexPath.row]];
<强>说明:强>
由于picData NSArray
包含NSString
,因此当您实际需要NSString
对象时,您将cell.imageView.image
对象传递给UIImage
。
这就是为什么现在它创建一个图像并传递它。 (imageNamed:
方法兑现图像)