Navigation Bar 按鈕 切換 編輯/收工 進入編輯模式
1. 定義兩個全域變數
UIBarButtonItem *goEdit;
UIBarButtonItem *doneEdit;
2. viewDidLoad編輯 並寫一個doSomething方法
//設定goEdit/doneEdit按鈕外觀及觸發事件
goEdit = [[UIBarButtonItem alloc] initWithTitle:@"編輯" style:UIBarButtonItemStylePlain target:self action:@selector(doSomething:)];
doneEdit = [[UIBarButtonItem alloc] initWithTitle:@"收工" style:UIBarButtonItemStylePlain target:self action:@selector(doSomething:)];
self.navigationItem.rightBarButtonItem = goEdit;
-(void) doSomething:(UIBarButtonItem*)sender{
// if(tbView.isEditing){
// [tbView setEditing:NO animated:YES];
// }else{
// [tbView setEditing:YES animated:YES];
// }
// 等同上面
//切換按鈕文字
[tbView setEditing:!(tbView.isEditing) animated:YES];
self.navigationItem.rightBarButtonItem = (tbView.isEditing)?doneEdit:goEdit;
}
留言
張貼留言