ios - 如何在 Objective-C 的 AlertView 中通过 http url 显示图像?

标签 ios objective-c uiimage uialertview nsurl

我正在用 Objective-C 开发,我想在 AlertView 中通过 http url 显示图像?

我已经得到像这样的图片 url:http://192.72.1.1/DCIM/100__DSC/SNAP0053.JPG ,并转换 NSURLNSString。但是我无法在 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并没有像下图那样显示任何图像。 enter image description here

我是不是漏掉了什么?

如何在 Objective-C 的 AlertView 中通过 http url 显示图像?

最佳答案

您不能在 AlertView 中添加图像。 在 iOS 7 之前是可能的。 您可以创建自定义 AlertView 并向其添加图像。

也看看这个

https://github.com/wimagguc/ios-custom-alertview

关于ios - 如何在 Objective-C 的 AlertView 中通过 http url 显示图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28426868/

相关文章:

ios Unity 3d 集成到 native ios 代码中

ios - 如何确定 EKCalendar 是 Facebook 日历?

ios - 如何在 iOS Swift 中获取应用程序的 CFBundleURLSchemes

iOS 应用程序无法在设备上正确显示

ios - UIImageView 未显示在 MKMapView 之上

iphone - 可编辑的 UITableView

ios - Apple 如何生成推送通知 token

iphone - sqlite3 因第二个插入语句而崩溃

ios - 如何在 iOS 中创建和检索新的位图

objective-c - 如何从 imagePickerController 属性保存 UIImage