【发布时间】:2015-04-10 04:50:35
【问题描述】:
我正在使用 Objective-C 进行开发,我想通过 http url 在 AlertView 中显示图像?
我已经得到了像:http://192.72.1.1/DCIM/100__DSC/SNAP0053.JPG这样的图片网址,并将NSURL转换为NSString。但我无法在 AlertView 中显示图像,它是空的。
将url转换为NSString并显示在AlertView中的代码如下:
NSString *path = [url absoluteString];
NSData * imageData = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString: path]];
UIImage *Image=[UIImage imageWithData:imageData];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Image" message:nil delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
UIImageView *imageView = [[UIImageView alloc] init];
[imageView setImage:Image];
[alert addSubview:imageView];
[alert show];
但是 AlertView 没有显示如下图所示的任何图像。
我错过了什么吗?
如何在 Objective-C 的 AlertView 中通过 http url 显示图片?
【问题讨论】:
-
自 iOS7 起,您可以将子视图添加到
UIAlertView(如果我没有记错的话)。您必须使用自定义UIAlertView(GitHub 上的许多项目都具有相同的行为) -
试过这个stackoverflow.com/a/2323694?我认为你没有设置它的 x,y,width 和 height 属性
标签: ios objective-c uiimage uialertview nsurl