Swift: Passing a parameter to selector

后端 未结 2 1811
别那么骄傲
别那么骄傲 2020-12-29 13:46

Using Swift 3, Xcode 8.2.1

Method:

func moveToNextTextField(tag: Int) {
   print(tag)
}

The lines below compile fine, but tag

2条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-29 14:39

    You cannot pass a custom parameter through a Timer action.

    Either

    #selector(moveToNextTextField)
    ...
    func moveToNextTextField()
    

    or

    #selector(moveToNextTextField(_:))
    ...
    func moveToNextTextField(_ timer : Timer)
    

    is supported, nothing else.

    To pass custom parameters use the userInfo dictionary.

提交回复
热议问题