謝謝大家。我發現真正有效的代碼。它看起來像:UIBarButtonItem操作不起作用。爲什麼?
- (void)viewDidLoad {
[super viewDidLoad];
UIButton* infoButton = [UIButton buttonWithType: UIButtonTypeInfoLight];
[infoButton addTarget:self action:@selector(settingsClick) forControlEvents:UIControlEventTouchDown];
UIBarButtonItem* theSettingsButton =[[UIBarButtonItem alloc]initWithCustomView:infoButton];
[self.toolbar setItems:[NSArray arrayWithObjects:theSettingsButton,nil]];
[theSettingsButton release];
}
究竟什麼是問題呢?代碼是否編譯?按鈕出現了嗎?按下它什麼都不做?按下它會導致你的應用程序崩潰? – deanWombourne 2011-06-16 11:18:02
是什麼,如果你做'NSLog(@「%@」,self.toolBar)'是'無';你有沒有在界面生成器中正確連線? – deanWombourne 2011-06-16 11:20:59