如何在 UITableView
的多个单元格中添加一张图片?
我将一张图片添加到一个顶部单元格,如下所示:
但是滚动到底部和顶部后我看到了这个:
第二个和第三个单元格的 z-index 比第一个单元格大。
我该怎么做?
谢谢..
最佳答案
UIImageView *imgView = [[UIImageView alloc]initWithFrame:CGRectMake(3,2, 20, 25)];
imgView.image=[UIImage imageNamed:@"img.png"];
[cell addSubview:imv];
你也不能直接将图像添加到单元格
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
static NSString* CellIdentifier = @"Cell";
UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
cell = [[[UITableViewCell alloc] UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.textLabel.text = @"I'm a UITableViewCell!";
cell.imageView.image = [UIImage imageNamed:@"image.png"];
return cell;
}
试试这段代码....
并调整图片大小....
关于iphone - 如何在 UITableView 单元格上添加图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18312969/