2
我有一个自定义单元格。它有一个UIImageView和一个按钮。当我点击按钮时,我的应用会将我的图像保存到相册并显示结果提醒。用自定义单元格快速显示警报
这里我的代码:
@IBAction func saveImage(sender: UIButton) {
UIImageWriteToSavedPhotosAlbum(self.photo.image!, self, "saveImageToLibrary:didFinishSavingWithError:contextInfo:", nil)
}
func saveImageToLibrary(image: UIImage, didFinishSavingWithError error: NSError?, contextInfo:UnsafePointer<Void>) {
let vc = ViewController()
if error == nil {
let ac = UIAlertController(title: "Saved!", message: "Image has been saved to your photos.", preferredStyle: .Alert)
ac.addAction(UIAlertAction(title: "OK", style: .Default, handler: nil))
vc.presentViewController(ac, animated: true, completion: nil)
} else {
let ac = UIAlertController(title: "Save error", message: error?.localizedDescription, preferredStyle: .Alert)
ac.addAction(UIAlertAction(title: "OK", style: .Default, handler: nil))
vc.presentViewController(ac, animated: true, completion: nil)
}
}
但是,当我点击的tableview我保存按钮,将其与气候变暖成功保存图像:
Warning: Attempt to present <UIAlertController: 0x7fa452f74ee0> on <Test.ViewController: 0x7fa452f56f40> whose view is not in the window hierarchy!
我如何可以调用从自定义单元格的警告?
谢谢。我尝试并取得成功。 – Ashley
你可能想让委托对象成为一个弱变量以避免数据泄露 –