gpt4 book ai didi

iphone - 从网络获取图像到 UIImageView 不起作用

转载 作者:行者123 更新时间:2023-11-28 18:13:47 25 4
gpt4 key购买 nike

我有一个非常简单的代码的大问题。我需要从 Facebook URL 获取图片并将其放在 UIImageView 上。

我不知道,但行不通。我也尝试了不同的链接(没有 Facebook 链接也不起作用)。

-(IBAction)setUserPhoto:(id)sender{

NSURL *url = [url initWithString:@"http://graph.facebook.com/100000769380612/picture?type=large"];
NSData *imageData = [NSData dataWithContentsOfURL:url];
UIImage *image = [UIImage imageWithData:imageData];

if(image){

NSLog(@"Image OK");

} else if (!image) {

NSLog(@"Error");

}

[userPhoto setImage:image];

}

谢谢。

最佳答案

字符串中有一个替换变量,尚未被替换:

http://graph.facebook.com/%@/picture?type=large

您缺少别名(如果我将此 url 放入 safari,则会出现此错误)

使用

NSString *urlString = [NSString stringWithFormat:@"http://graph.facebook.com/%@/picture?type=large", replacement]; //where replacement is the string that is supposed to go there
NSUrl *url = [NSUrl URLWithString:urlString];

首先在网络浏览器中尝试 url,以确保它存在。

关于iphone - 从网络获取图像到 UIImageView 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9820621/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com