将图像添加到表格单元格(iOS)

我正在尝试做类似于Twitter或Facebook的事情。

- (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:@"MyReallyCoolImage.png"]; return cell; } 

感谢Thomas Moore

添加图像到UItableView

那么,要添加一个图像到一个表单元格,你可以添加一个UIImage到字幕UITableViewCell的图像属性或你自己的自定义单元格。 我会阅读在developer.apple.com上定制UITableViewCells的文档。

Swift版本:

 override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as UITableViewCell cell.textLabel.text = "I'm a UITableViewCell!"; cell.textLabel.textColor = UIColor.whiteColor() cell.imageView.image = UIImage(named: "MyReallyCoolImage.png") return cell; }