【问题标题】:UIImageView from NSURL is Blank来自 NSURL 的 UIImageView 为空白
【发布时间】:2018-11-25 09:19:42
【问题描述】:

尝试显示来自 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

【问题讨论】:

    标签: ios objective-c uiimageview uiimage uikit


    【解决方案1】:

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

    - (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;
        }
    }
    

    【讨论】:

    • 完美!非常感谢:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-11-19
    • 1970-01-01
    • 2015-09-08
    • 2016-12-18
    • 2012-04-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多