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

查看:85
本文介绍了将图像添加到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:delegate方法中配置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天全站免登陆