Swift 3:无法识别的选择器发送到实例Xcode 8 [英] Swift 3: Unrecognized selector sent to instance Xcode 8

查看:143
本文介绍了Swift 3:无法识别的选择器发送到实例Xcode 8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经以编程方式创建了一个 UIView ,并向其添加了 UIPanGestureRecognizer

I have programmatically created an UIView and added UIPanGestureRecognizer to it:

class ViewController: UIViewController{
    var preludeView: UIView!

    override func viewDidLoad() {
        super.viewDidLoad()

        initViews()
        createConstrants()

        let panGestureRecognizer = UIPanGestureRecognizer(target: self, action: Selector(("handleTap:")))
        preludeView.addGestureRecognizer(panGestureRecognizer)
    }

    func handleTap(recognizer: UIPanGestureRecognizer) {
        print("WORKING!!!!")
    }

    func initViews() {
        ...
    }

    func createConstrants() {
        ...
    }
}

但是当我触摸视图时,Xcode会抛出一个错误:

But when I am touching the view Xcode is throwing an error:


2016-07-13 09:24:29.918 Draft_Hypa_02 [661:83024]
- [Draft_Hypa_02.ViewController handleTap:]:无法识别的选择器发送到实例0x17d94a10 2016-07-13 09:24:29.921
Draft_Hypa_02 [661:83024] *终止应用由于未被捕获的异常
'NSInvalidArg umentException',原因:' - [Draft_Hypa_02.ViewController
handleTap:]:无法识别的选择器发送到实例0x17d94a10'
*
第一次抛出调用堆栈:(0x249cf91b 0x2416ae17 0x249d52b5 0x249d2ee1 0x248fe238 0x294ae9eb 0x290e984f 0x28f7aff1 0x294afd4f
0x28f3ba57 0x28f38017 0x28f78ec9 0x28f7867b 0x28f49125 0x28f476d3
0x24991dff 0x249919ed 0x2498fd5b 0x248df229 0x248df015 0x25ecfac9
0x28fb1189 0x93144 0x24587873)libc ++ abi.dylib:以
终止$ NSException类型的未捕获异常

2016-07-13 09:24:29.918 Draft_Hypa_02[661:83024] -[Draft_Hypa_02.ViewController handleTap:]: unrecognized selector sent to instance 0x17d94a10 2016-07-13 09:24:29.921 Draft_Hypa_02[661:83024] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Draft_Hypa_02.ViewController handleTap:]: unrecognized selector sent to instance 0x17d94a10' * First throw call stack: (0x249cf91b 0x2416ae17 0x249d52b5 0x249d2ee1 0x248fe238 0x294ae9eb 0x290e984f 0x28f7aff1 0x294afd4f 0x28f3ba57 0x28f38017 0x28f78ec9 0x28f7867b 0x28f49125 0x28f476d3 0x24991dff 0x249919ed 0x2498fd5b 0x248df229 0x248df015 0x25ecfac9 0x28fb1189 0x93144 0x24587873) libc++abi.dylib: terminating with uncaught exception of type NSException

但是,如果我删除 handleTap 函数中的参数并删除<$中的冒号c $ c>选择器((handleTap:)),一切正常!

However, if I remove argument in the handleTap function and remove the colon in the Selector(("handleTap:")), everything works fine!

已经花了一天的时间来解决这个问题非常感谢您的帮助!

Already spent a day to try to fix this issue and would be very appreciate for your help!

推荐答案

如果您使用 swift 3你的选择器应该是这样的

If you are using swift 3 your selector should be like this

#selector(self.handleTap(recognizer:))

这篇关于Swift 3:无法识别的选择器发送到实例Xcode 8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆