【问题标题】:Objective-C UITableView cell imageObjective-C UITableView 单元格图像
【发布时间】:2013-09-03 14:31:03
【问题描述】:

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

【问题讨论】:

    标签: ios objective-c uitableview uiimage


    【解决方案1】:

    将:(@"http://graph.facebook.com/%@/picture", thisFriend.friendID) 替换为:

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

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

    【讨论】:

    • 成功了。对我来说多么尴尬!谢谢贝克:)
    • 这件事发生在我们所有人身上!
    • 这是另一个简单的问题:我怎样才能让它变成这样:cell.imageView.image = [UIImage thisFriend.friendPhoto];
    • [UIImage imageWithContentsOfFile:thisFriend.friendPhoto],但我认为您必须确保friendPhoto 包含图像的完整路径。
    • 那么就用赋值... cell.imageView.image = thisFriend.friendPhoto;我认为通过 Apple 表视图示例代码对您有很大帮助。
    【解决方案2】:

    试试

    cell.imageView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:
        [NSURL URLWithString:[NSString stringWithFormat:@"http://graph.facebook.com/%@/picture", thisFriend.friendID]]]];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-16
      • 1970-01-01
      • 2011-08-17
      • 2012-06-27
      • 1970-01-01
      相关资源
      最近更新 更多