如何为我的表格视图的每个单元格设置不同的图像。我想通过图像名称数组来做到这一点
问问题
952 次
4 回答
6
使用以下代码...
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
/* Initialise the cell */
static NSString *CellIdentifier = @"MyTableViewCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
/* Configure the cell */
NSString *cellImageName = [[self cellImageNames] objectAtIndex:[indexPath row]];//cellImageNames ism image names array where
UIImage *cellImage = [UIImage cellImageName];
[[cell imageView] setImage:cellIcon];
// Other cell configuration code...
return cell;
}
希望对你有帮助...
于 2012-04-28T10:33:15.253 回答
5
例如:
cell.imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"image%i.png", indexPath.row]];
或者
cell.imageView.image = (UIImage *)[yourArray objectAtIndex:indexPath.row];
于 2012-04-28T10:34:02.087 回答
5
您的解决方案在这里转到此链接 如何在 UITableView 中添加 UIImage
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *MyIdentifier = @"MyIdentifier";
MyIdentifier = @"TableView";
MainView *cell = (MainView *)[tableView dequeueReusableCellWithIdentifier: MyIdentifier];
if(cell == nil) {
[[NSBundle mainBundle] loadNibNamed:@"MainView" owner:self options:nil];
cell = tableCell;
}
[cell LabelText:[arryList objectAtIndex:indexPath.row]];
[cell ProductImage:[imagesList objectAtIndex:indexPath.row]];
return cell;
}
带有图像的 Utableview 显示如下
于 2012-04-28T10:34:40.603 回答
-1
cell.imageView.image = [UIImage imageNamed:@"image.png"];
于 2013-03-26T06:55:52.043 回答