有什么办法可以在我已经显示的UIAlertController动作中显示来自Web URL的图像。真正的场景是我展示了UIAlertController,并且我从URL并排获取图像。但是现在我想在下载图像后更新UIAlertAction,但是它们没有更新。
稍后,如果我打开UIAlertController,则这些图像将显示在UIAlertAction中。
let alertController = UIAlertController(title: "My App", message: "Select option:", preferredStyle: .actionSheet)
for url in arrUrl {
let action = UIAlertAction(title: "url", style: .default) { (action) in
}
downloadImage(url) { (image) in
if image != nil {
action.setValue(image, forKey: "image")
}
}
alertController.addAction(action)
}
func downloadImage(_ strUrl: String, completionHandler: @escaping(_ image: UIImage?) -> ()) {
SDWebImageManager.shared().loadImage(
with: URL(string: strUrl),
options: .highPriority,
progress: nil) { (image, data, error, cacheType, isFinished, imageUrl) in
completionHandler(image)
}
}
答案 0 :(得分:0)
是的,可以这样做。您可以扩展您引用的博客文章(https://medium.com/@maximbilan/ios-uialertcontroller-customization-5cfd88140db8)上使用的模式。
可以使用UISwitch
来代替UIImageView
。您可以将保存UIViewController
UIImageView
的{{1}}保存在当前的视图控制器中。
获取图像后,您可以更新IBOutlet
的{{1}}属性。
免责声明:
我很确定此image
业务是不受支持的黑客活动,因为UIImageView
属性似乎没有记录在案。因此,尽管这可能在今天起作用,但它随时可能中断。提交到AppStore时也可能会被拒绝。
使用后果自负