Ios 没有使用Objective-C选择器声明方法';methodName()';在Swift 2.2中

Ios 没有使用Objective-C选择器声明方法';methodName()';在Swift 2.2中,ios,swift,Ios,Swift,我在类中名为Toolbar setup的函数中设置UIToolBar public class Utility { func toolBarSetup(inout toolBar: UIToolbar, inout toolBarLbl: UILabel, view: UIView) -> (UIToolbar, UILabel){ toolBar = UIToolbar(frame: CGRectMake(0, view.frame.height/7,

我在类中名为Toolbar setup的函数中设置UIToolBar

public class Utility {      

  func toolBarSetup(inout toolBar: UIToolbar, inout  toolBarLbl: UILabel, view: UIView) -> (UIToolbar, UILabel){ 

      toolBar = UIToolbar(frame: CGRectMake(0, view.frame.height/7, view.frame.width, 44.0)) 

      let toolBar_btn = UIBarButtonItem(title: "Cancel", style: UIBarButtonItemStyle.Plain, target: self, action: "picker_cancel")

     //Codes to setup toolbar label

     toolBar.setItems([toolBar_btn, flexSpace, text_info, flexSpace], animated: true)

      return (toolBar, lbl_toolBar_cancel)
 }

}
从另一个类我调用这个函数

class Class1: UIViewController {

  var toolBar = UIToolbar()
  var lbl_toolBar = UILabel()

  override func viewDidLoad() {
    super.viewDidLoad()

    let toolBarSetup = Utility().toolBarSetup(&toolBar, lbl_toolBar: &lbl_toolBar, view: view)

    toolBar = toolBarSetup.0
    lbl_toolBar = toolBarSetup.1
  }

  func picker_cancel(){

  }
}
前面的函数picker_cancel()工作正常,但是昨天我更新了我的Xcode,之后我收到了这个警告

没有使用Objective-C选择器“picker_cancel()”声明任何方法。

在“实用程序”类的下面一行中

let toolBar_btn = UIBarButtonItem(title: "Cancel", style: UIBarButtonItemStyle.Plain, target: self, action: "picker_cancel")

我试图通过使用选择器来解决问题,但没有任何效果。请提供帮助。

在Xcode 7.3中,您需要使用#选择器()。通常Xcode可以为您进行此更改

我认为这是可行的:

#selector(Class1.picker_cancel)

您需要在实用程序类中具有该方法<代码>目标:self指的是发送消息的对象。@Danny Bravo许多验证都在picker_cancel()函数下进行,并且所有验证都依赖于Class1。@vsvishnu请不要在您的问题中添加其他问题。你对这个问题有一个答案-如果你有另一个不同的问题,问另一个问题。谢谢。@Eric亲爱的,我正试图再次亲自解决这个问题。如果什么都不起作用,我肯定会问另一个问题:)谢谢。我想重用这个toolBarSetup()函数,因为我需要实现30多个类,所以不同的类会调用toolBarSetup()函数。