Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/103.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios NSURL中的UIImageView为空_Ios_Objective C_Uiimageview_Uiimage_Uikit - Fatal编程技术网

Ios NSURL中的UIImageView为空

Ios NSURL中的UIImageView为空,ios,objective-c,uiimageview,uiimage,uikit,Ios,Objective C,Uiimageview,Uiimage,Uikit,我没有收到任何错误,试图显示从一个URL的图像,但没有显示任何东西。在尝试显示图像之前,是否必须在本地下载图像?请原谅我的无知,我是一个完全的iOS开发新手哈哈 - (void) viewDidLoad { NSData *dataBuff = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString:@"https://i1.wp.com/www.penelopeperu.com/wp-content/uploads

我没有收到任何错误,试图显示从一个URL的图像,但没有显示任何东西。在尝试显示图像之前,是否必须在本地下载图像?请原谅我的无知,我是一个完全的iOS开发新手哈哈

- (void) viewDidLoad {
        NSData *dataBuff = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString:@"https://i1.wp.com/www.penelopeperu.com/wp-content/uploads/2017/08/Screen-Shot-2017-08-22-at-7.24.16-AM-e1503412089169.png"]];
        UIImage * imgBuffer = [[UIImage alloc] initWithData:dataBuff];
        img = [[UIImageView alloc] initWithImage:imgBuffer];
        img.image = randImgBuffer;
    }
}

img
在我的头文件中定义为
UIImageView

代码中的问题尝试此解决方案

- (void) viewDidLoad {
        NSData *dataBuff = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString:@"https://i1.wp.com/www.penelopeperu.com/wp-content/uploads/2017/08/Screen-Shot-2017-08-22-at-7.24.16-AM-e1503412089169.png"]];
        UIImage * imgBuffer = [[UIImage alloc] initWithData:dataBuff];
        img.image = imgBuffer;
    }
}

完美的非常感谢:)