How can i resolve this Error :unrecognised selector sent to instance (LongPress onUIImageView)
How can i resolve this Error :unrecognised selector sent to instance (LongPress onUIImageView)
原因:'-[HMIS_ios.ImageViewerVController longPressed:]:无法识别的选择器发送到实例 0x7fe865576d70'
class ImageViewerVController: UIViewController {
@IBOutlet weak var ImageViewer: UIImageView!
var pass = ""
override func viewDidLoad() {
super.viewDidLoad()
print("URL:" + pass)
self.ImageViewer.sd_setImage(with: URL(string:"\(pass)"))
ImageViewer.isUserInteractionEnabled = true
let longPressRecognizer = UILongPressGestureRecognizer(target: self, action: Selector(("longPressed:")))
longPressRecognizer.minimumPressDuration = 0.5
self.ImageViewer.addGestureRecognizer(longPressRecognizer)
}
@objc func longPressed(sender: UILongPressGestureRecognizer) {
UIImageWriteToSavedPhotosAlbum(ImageViewer.image!, self, Selector(("image:didFinishSavingWithError:contextInfo:")), nil)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
我想使用 UILongPressGestureRecognizer 在图库中保存图片
改变
let longPressRecognizer = UILongPressGestureRecognizer(target: self, action: Selector(("longPressed:")))
UIImageWriteToSavedPhotosAlbum(ImageViewer.image!, self, Selector(("image:didFinishSavingWithError:contextInfo:")), nil)
到
let longPressRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(longPressed(sender:)))
UIImageWriteToSavedPhotosAlbum(ImageViewer.image!, self, #selector(image(_:didFinishSavingWithError:contextInfo:)), nil)
像这样改变didFinishSavingWithError
方法
@objc func image(_ image: UIImage, didFinishSavingWithError error: NSError?, contextInfo: UnsafeRawPointer) {
if let error = error {
print(error.localizedDescription)
} else {
print("image saved")
}
}
原因:'-[HMIS_ios.ImageViewerVController longPressed:]:无法识别的选择器发送到实例 0x7fe865576d70'
class ImageViewerVController: UIViewController {
@IBOutlet weak var ImageViewer: UIImageView!
var pass = ""
override func viewDidLoad() {
super.viewDidLoad()
print("URL:" + pass)
self.ImageViewer.sd_setImage(with: URL(string:"\(pass)"))
ImageViewer.isUserInteractionEnabled = true
let longPressRecognizer = UILongPressGestureRecognizer(target: self, action: Selector(("longPressed:")))
longPressRecognizer.minimumPressDuration = 0.5
self.ImageViewer.addGestureRecognizer(longPressRecognizer)
}
@objc func longPressed(sender: UILongPressGestureRecognizer) {
UIImageWriteToSavedPhotosAlbum(ImageViewer.image!, self, Selector(("image:didFinishSavingWithError:contextInfo:")), nil)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
我想使用 UILongPressGestureRecognizer 在图库中保存图片
改变
let longPressRecognizer = UILongPressGestureRecognizer(target: self, action: Selector(("longPressed:")))
UIImageWriteToSavedPhotosAlbum(ImageViewer.image!, self, Selector(("image:didFinishSavingWithError:contextInfo:")), nil)
到
let longPressRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(longPressed(sender:)))
UIImageWriteToSavedPhotosAlbum(ImageViewer.image!, self, #selector(image(_:didFinishSavingWithError:contextInfo:)), nil)
像这样改变didFinishSavingWithError
方法
@objc func image(_ image: UIImage, didFinishSavingWithError error: NSError?, contextInfo: UnsafeRawPointer) {
if let error = error {
print(error.localizedDescription)
} else {
print("image saved")
}
}