是否可以将图像添加到表格 View 中?到左边?如果是这样,它的尺寸应该是多少?
最佳答案
不需要自定义 UITableViewCell 即可简单地将图像添加到单元格的左侧。只需在 tableView:cellForRowAtIndexPath: 委托(delegate)方法中配置 UITableView 单元格的 imageView 属性,如下所示:
- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
static NSString* CellIdentifier = @"Cell";
UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.textLabel.text = @"I'm a UITableViewCell!";
cell.imageView.image = [UIImage imageNamed:@"MyReallyCoolImage.png"];
return cell;
}
除非您在 UITableViewDelegate 中提供 tableView:heightForRowAtIndexPath: 方法,否则 UITableViewCell 的默认高度为 44 点,在非视网膜显示屏上为 44 像素,在视网膜显示屏上为 88 像素。
关于iphone - 将图像添加到 UItableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4999017/