ios - Objective-C UITableView单元格图像

标签 ios objective-c uitableview uiimage

因此,我有一个Facebook Friends的 UITableView ,对于一个单元格,我想向其中添加图像。

当我尝试以下代码时:

cell.imageView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:
[NSURL URLWithString: (@"http://graph.facebook.com/shaverm/picture")]]];

一切正常。虽然这是对图像目标进行硬编码,但是当我做这样的事情时:
cell.imageView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:
[NSURL URLWithString: (@"http://graph.facebook.com/%@/picture", thisFriend.friendID)]]];

它给我一个警告,指出“未使用表达式结果”,同时指向链接前的@符号。

任何想法为什么会这样?

我也尝试过:
cell.imageView.image = [UIImage imageNamed:thisFriend.friendPhoto];

但这给了我一个“不兼容的指针类型,将UIImage发送到NSString类型的参数”警告。

最佳答案

用以下内容替换:(@"http://graph.facebook.com/%@/picture", thisFriend.friendID):

[NSString stringWithFormat:@"http://graph.facebook.com/%@/picture", thisFriend.friendID];

看起来您只是忘记了格式化字符串的方法。

关于ios - Objective-C UITableView单元格图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18594884/

相关文章:

ios - 带导航 Controller 的模态视图

ios - Facebook 登录后无法推送到 PFQueryTableViewController

iphone - PerformSelectorOnMainThread 抛出消息已释放

iphone - 如何在 iPhone 上移动 MkMapView.userLocation?

ios - UITableViewCell 有很多 subview 或单个 View

ios - UITableView Swift 2 中的自定义单元格

ios - 在 Xamarin Objective C 绑定(bind)中调用委托(delegate)时出现异常

ios - 无法在不创建新实例的情况下导航回原始选项卡

ios - UITableView 自定义单元格在尝试滚动时消失

ios - 计算固定行数和表格高度的行高