将图像添加到 UItableView [英] adding images to UItableView

查看:41
本文介绍了将图像添加到 UItableView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将图像添加到表格视图中?到左边?如果是这样,它应该是什么尺寸?

Is it possible to add images to a table view? To the left side? And if so, what size should it be?

推荐答案

自定义 UITableViewCell 不需要简单地将图像添加到单元格的左侧.只需在 tableView:cellForRowAtIndexPath: 委托方法中配置 UITableView 单元格的 imageView 属性,如下所示:

A custom UITableViewCell is not required to simply add an image to the left side of the cell. Simply configure the imageView property of the UITableView cell in your tableView:cellForRowAtIndexPath: delegate method like so:

- (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 像素.

Unless you provide a tableView:heightForRowAtIndexPath: method in your UITableViewDelegate, the default height of a UITableViewCell is 44 points, which is 44 pixels on a non-retina display and 88 pixels on a retina display.

这篇关于将图像添加到 UItableView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆