gpt4 book ai didi

ios - UIImageWriteToSavedPhotosAlbum 选择器语法问题

转载 作者:搜寻专家 更新时间:2023-10-30 21:48:51 26 4
gpt4 key购买 nike

努力让 UIImageWriteToSavedPhotosAlbum 快速工作 https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIKitFunctionReference/index.html#//apple_ref/c/func/UIImageWriteToSavedPhotosAlbum

遗憾的是,该文档仅在 Objective-C 中。

这是我的代码:

func saveImage()
{
UIImageWriteToSavedPhotosAlbum(uiimage, self, "saveImageComplete:::", nil)
}

func saveImageComplete(image:UIImage,err:NSError,context:UnsafePointer<()>)
{
loadLastPhotoIntoGalleryIcon()
}

但问题是它会抛出带有无法识别的选择器的 NSInvalidArgumentException:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', 
reason: 'app.PhotoEditor<0x14a1e400> does not respond to selector
saveImageComplete:::'

你能告诉我我的语法有什么问题以及我如何正确指定这个选择器吗?据我了解,每个 : 代表该方法期望的 1 个参数,因为它有 3 个参数,所以我给了它 3 个:。

谢谢!

最佳答案

以上均不适用于 Swift3。为那些正在努力使用 Swift3 语法

的人试试这个

行动:

@IBAction func saveToPhotos(_ sender: AnyObject) {

UIImageWriteToSavedPhotosAlbum(yourImageView.image!, self, #selector(image(_:didFinishSavingWithError:contextInfo:)), nil)
}

目标:

func image(_ image: UIImage, didFinishSavingWithError error: Error?, contextInfo: UnsafeRawPointer) {

if error == nil {
let ac = UIAlertController(title: "Saved!", message: "Image saved to your photos.", preferredStyle: .alert)
ac.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
present(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))
present(ac, animated: true, completion: nil)
}
}

请参阅此链接以获得更多说明 https://www.hackingwithswift.com/read/13/5/saving-to-the-ios-photo-library

关于ios - UIImageWriteToSavedPhotosAlbum 选择器语法问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27387525/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com