2

I setup a UIToolBar inside a function named toolBarSetup inside a class.

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)
 }

}

From another class I'm calling this function

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(){

  }
}

Earlier the function picker_cancel() was working fine but yesterday I have updated my Xcode after that I'm getting this warning

No method declared with Objective-C selector 'picker_cancel()'

in the below line of class 'Utility'.

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

I tried to solve by using selector but nothing worked. Please help.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
vsvishnu
  • 133
  • 1
  • 2
  • 11
  • You need to have the method in the utility class. `target: self` refers to the object that's being sent the message. – Danny Bravo Mar 23 '16 at 10:15
  • @Danny Bravo Many validations are coming under the picker_cancel() function and all validations are depend on Class1. – vsvishnu Mar 23 '16 at 10:24
  • @vsvishnu Please do not add another different question to your question. You had an answer for this one - if you have another different question, *ask another question*. Thank you. – Eric Aya Mar 23 '16 at 10:37
  • 1
    @ Eric Dear I'm trying to solve this issue myself again. If nothing works I will definitely ask another question :) Thank you. – vsvishnu Mar 23 '16 at 10:55

1 Answers1

11

In Xcode 7.3 you need to use the #selector(). Normally Xcode can do this change for you.

I think that works:

#selector(Class1.picker_cancel)
dungi
  • 302
  • 3
  • 7
  • I want to reuse this toolBarSetup() function because more than 30 classes I have to implement UIToolBar so different classes will call toolBarSetup() function. – vsvishnu Mar 23 '16 at 10:49