If I am not wrong you have declared your backButtonPressed
method inside another method like this:
override func viewDidLoad() {
super.viewDidLoad()
let button = UIButton(frame: CGRectMake(150, 240, 75, 30))
button.setTitle("Next", forState: UIControlState.Normal)
button.addTarget(self, action: Selector("backButtonPressed:"), forControlEvents: UIControlEvents.TouchUpInside)
button.backgroundColor = UIColor.greenColor()
self.view.addSubview(button)
func backButtonPressed(sender:AnyObject?) {
print("Called")
}
// Do any additional setup after loading the view, typically from a nib.
}
This is wrong way.
Declare your method outside as shown in below code:
override func viewDidLoad() {
super.viewDidLoad()
let button = UIButton(frame: CGRectMake(150, 240, 75, 30))
button.setTitle("Next", forState: UIControlState.Normal)
button.addTarget(self, action: Selector("backButtonPressed:"), forControlEvents: UIControlEvents.TouchUpInside)
button.backgroundColor = UIColor.greenColor()
self.view.addSubview(button)
}
func backButtonPressed(sender:AnyObject?) {
print("Called")
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…