你好,我添加了一个快速的手势识别器,它不断崩溃我的程序
// MARK: Floating Button
var roundButton = UIButton()
func createFloatingButton() {
self.roundButton = UIButton(type: .custom)
self.roundButton.setTitleColor(UIColor.orange, for: .normal)
self.roundButton.addTarget(self, action: #selector(ButtonClick(_:)), for: UIControlEvents.touchUpInside)
//change view to navigationController?.view, if you have a navigationController in this tableview
self.navigationController?.view.addSubview(roundButton)
}
override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
roundButton.layer.cornerRadius = roundButton.layer.frame.size.width/2
roundButton.backgroundColor = UIColor.lightGray
roundButton.clipsToBounds = true
roundButton.setImage(UIImage(named:"ic_wb_sunny_48pt"), for: .normal)
roundButton.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
roundButton.trailingAnchor.constraint(equalTo: self.view.trailingAnchor, constant: -3),
roundButton.bottomAnchor.constraint(equalTo: self.view.bottomAnchor, constant: -53),
roundButton.widthAnchor.constraint(equalToConstant: 50),
roundButton.heightAnchor.constraint(equalToConstant: 50)])
}
这是我得到的错误
2017-09-08 20:17:33.355 Views[40942:2309262] -[Views.ViewController handleSwipes:]: unrecognized selector sent to instance 0x7fdd9bc0dc90 2017-09-08 20:17:33.361 Views[40942:2309262] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Views.ViewController handleSwipes:]: unrecognized selector sent to instance 0x7fdd9bc0dc90' *** First throw call stack: ( 0 CoreFoundation 0x0000000111f40b0b __exceptionPreprocess + 171 1 libobjc.A.dylib 0x000000010f1e6141 objc_exception_throw + 48 2 CoreFoundation 0x0000000111fb0134 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132 3 CoreFoundation 0x0000000111ec7840 ___forwarding___ + 1024 4 CoreFoundation 0x0000000111ec73b8 _CF_forwarding_prep_0 + 120 5 UIKit 0x000000010fbecf59 -[UIGestureRecognizerTarget _sendActionWithGestureRecognizer:] + 57 6 UIKit 0x000000010fbf4d57 _UIGestureRecognizerSendTargetActions + 109 7 UIKit 0x000000010fbf270b _UIGestureRecognizerSendActions + 225 8 UIKit 0x000000010fbf19ce -[UIGestureRecognizer _updateGestureWithEvent:buttonEvent:] + 981 9 UIKit 0x000000010fbde152 _UIGestureEnvironmentUpdate + 1219 10 UIKit 0x000000010fbddc43 -[UIGestureEnvironment _deliverEvent:toGestureRecognizers:usingBlock:] + 484 11 UIKit 0x000000010fbdce0a -[UIGestureEnvironment _updateGesturesForEvent:window:] + 274 12 UIKit 0x000000010f728eea -[UIWindow sendEvent:] + 4092 13 UIKit 0x000000010f6d5a84 -[UIApplication sendEvent:] + 352 14 UIKit 0x000000010feb95d4 __dispatchPreprocessedEventFromEventQueue + 2926 15 UIKit 0x000000010feb1532 __handleEventQueue + 1122 16 CoreFoundation 0x0000000111ee6c01 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17 17 CoreFoundation 0x0000000111ecc0cf __CFRunLoopDoSources0 + 527 18 CoreFoundation 0x0000000111ecb5ff __CFRunLoopRun + 911 19 CoreFoundation 0x0000000111ecb016 CFRunLoopRunSpecific + 406 20 GraphicsServices 0x0000000113ed7a24 GSEventRunModal + 62 21 UIKit 0x000000010f6b8134 UIApplicationMain + 159 22 Views 0x000000010ec06a67 main + 55 23 libdyld.dylib 0x0000000112f6c65d start + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)
答案 0 :(得分:2)
let leftSwipe = UISwipeGestureRecognizer(target: self, action: #selector(handleSwipes(sender:)))
@objc func handleSwipes(sender: UISwipeGestureRecognizer) {
// ...
}
这应该适用于Swift 3和4。