[英]Change UITableView Cell Image using IF Statement?
我想使用cell.imageView setImage:方法添加图像。 但是,根据数组中的字段(以NSString的形式,并使用[狗类型]调用),我需要单元格左侧的图像更改为反映狗类型的图像。
我该怎么做呢? 谢谢。
如您所知,要填充单元格内容,您必须使用委托方法:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
因此,您必须将IF放入此方法中,并使用indexPath.row来了解要绘制的女巫行。 这里有个简单的例子:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"] autorelease];
}
UIImage *a,*b; //Remeber to init with your images:)
if(indexPath.row == 1)
{
[cell.imageView setImage:a];
}
else
{
[cell.imageView setImage:b];
}
return cell;
}
我希望这就是你想要的:)
我认为您可以确定要做什么。
通过改变cellForRowAtIndexPath方法中的条件:
if(indexPath.row == 0) // for first cell of tableView
if(indexPath.row == 1) // for second cell of tableView
希望你能理解...
即使有任何问题也要发表评论...如果解决了就标记为正确...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.