読者です 読者をやめる 読者になる 読者になる

Satomi and Dogs

バーチャルな世界に住んでいた料理好きSatomiが美味しいご飯と犬と動物たちと牧草に囲まれた生活を目指す日記です

Watch log without any thoughts... What I forgot when I add action to button of navigation

I tried to add button in navigation bar. I tried to add action to the button. But I forgot to set UIButton sender to argument of action method.

This is my first experience to get trouble in this level. So I look back me so deeply.

In Logs,

2015-12-14 14:34:38.377 HogeController onClickBarButtonEdit:]: unrecognized selector sent to instance 
2015-12-14 14:34:38.389  *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Fuga.HogeViewController onClickBarButtonEdit:]: unrecognized selector sent to instance 0x7f8025c01a50'

Logs said the reason.... I should have watched Logs without any hot thoughts.

Below is succeeded example.

func viewDidLoad() {
・
・
    let barButtonEdit = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Edit, target: self, action: "onClickBarButtonEdit:")
    let barButtons: NSArray = [barButtonEdit]
    self.navigationItem.setRightBarButtonItems(barButtons as? [UIBarButtonItem], animated: true)
    }
・
・
}
  
func onClickBarButtonEdit(sender:UIButton) {
    print("hoge")
}