Neo*_*ang 1 selector ios swift
iOS API函数UIImageWriteToSavedPhotosAlbum将选择器作为一个参数:
func UIImageWriteToSavedPhotosAlbum(_ image: UIImage,
_ completionTarget: Any?,
_ completionSelector: Selector?,
_ contextInfo: UnsafeMutableRawPointer?)
Run Code Online (Sandbox Code Playgroud)
https://developer.apple.com/documentation/uikit/1619125-uiimagewritetosavedphotosalbum
但是,迅速地,当我调用此函数时,选择器永远不会被识别:
class Base {
func save_image(img:UIImage) {
UIImageWriteToSavedPhotosAlbum(img, self, Selector("image:didFinishSavingWithError:contextInfo:"), nil)
// I also tried this:
// UIImageWriteToSavedPhotosAlbum(img, self, #selector(image(_:didFinishSavingWithError:contextInfo:))
}
@objc func image(_ image: UIImage, didFinishSavingWithError error: Error?, contextInfo: UnsafeRawPointer) {
print("Photo Saved Successfully")
}
}
class Child:Base {
}
// This is how I call the save_image function:
let child = Child()
child.save_image()
Run Code Online (Sandbox Code Playgroud)
如您所见,我尝试根据签名和字符串构造选择器,但均无效。我总是在运行时收到此错误:
'XXX.Child' does not implement methodSignatureForSelector: -- trouble ahead
Unrecognized selector ......
Run Code Online (Sandbox Code Playgroud)
这是怎么回事 我想知道这是否是因为swift看不到Child类的方法,因为该方法是从Base类继承的?
如何成功通过选择器?
我读过的相关问题:
methodSignatureForSelector是NSObject的方法。因此,您需要继承NSObject该类。
class Base: NSObject {
...
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1509 次 |
| 最近记录: |