简体   繁体   中英

ios Cannot convert value of type '()' to expected argument type 'String' swift 3

在此处输入图片说明

I have updated my code to Swift 3 and now getting the error above. I think there is something wrong with the way selector is called. Anyone please help me, What is wrong.

只需使用swift 3选择器语法更改您的选择器语法,如下所示。

 #selector(self.hideKeyboard)

The syntax for Selector has been changed in Swift 3. You don't need to add round brackets after selector name if there is no parameter in the selector.

let tapGesture = UITapGestureRecognizer(target: self, action: #selector(hideKeyboard))
self.view.addGestureRecognizer(tapGesture)

For anyone looking for a solution can try this.

let tap = UITapGestureRecognizer(target: self, action: #selector(self.handleTap(_:)))
view.addGestureRecognizer(tap)

// function which is triggered when handleTap is called
 func handleTap(_ sender: UITapGestureRecognizer) {
     print("Hello World")
  }

I know it's loo late to answer, but it can help others.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM