如何在iphone中的tableview中添加图像

时间:2011-07-06 10:51:26

标签: iphone uiimageview uitableview

我必须在tableview中添加图片。我有2个列表一个用于twitter,第二个用于facebook。我想用图像图标显示每个列表。这是我在twitter表中附加值的代码。

   for (NSDictionary *wallText in sortedarray) {

    NSString *wallNameValue = [wallText objectForKey:@"message"];


    if(![[NSNull null] isEqual:wallNameValue] && [wallNameValue length])
    {


        [tableList addObject:wallNameValue];

    }

}

我想在行的左侧显示推特图片。我将如何添加图片。

提前致谢

3 个答案:

答案 0 :(得分:1)

尝试以这种方式使用:

cell.imageView.image = [UIImage imagedNamed:[wallText objectForKey:@"message"]];

&安培;加上没有必要为此运行任何循环。这是优化您的代码。

只需通过 indexpath.row

访问数组
NSDictionary *wallText = (NSDictionary *)[[sortedarray objectAtIndex:indexPath.row]valueForKey:message];

希望你能在 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath。

中做所有这些事情。

答案 1 :(得分:0)

在表视图的委托中,在设置UITableViewCell的方法中,执行以下操作:

cell.imageView.image = myImage;
// myImage is a UIImage *.

每个UITableViewCell都内置了一个UIImageView,可以在单元格的左侧为您显示图像。

参考: http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UITableViewCell_Class/Reference/Reference.html

答案 2 :(得分:0)

cellForRowAtIndexPath中执行

cell.imageView.image = [UIImage imageWithData:[yourImageDataArray objectAtIndex:indexPath.row]];