2011-03-06 131 views

回答

1

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

18
- (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

adding images to UItableView

0

斯威夫特版本:

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; 
} 
相关问题