1

所以我有一个Facebook 好友的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 类型的参数”警告。

4

2 回答 2

2

替换:(@"http://graph.facebook.com/%@/picture", thisFriend.friendID)用这个:

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

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

于 2013-09-03T14:32:59.383 回答
1

尝试

cell.imageView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:
    [NSURL URLWithString:[NSString stringWithFormat:@"http://graph.facebook.com/%@/picture", thisFriend.friendID]]]];
于 2013-09-03T14:32:33.987 回答