편집에서 완료로 변경할 수있는 버튼 하나를 만듭니다. 더 많은 iPhone 개발 도서의 팁입니다.
- (void)viewDidLoad {
[super viewDidLoad];
UIBarButtonItem *editButton = self.editButtonItem;
[editButton setTarget:self];
[editButton setAction:@selector(toggleEdit)];
self.navigationItem.leftBarButtonItem = editButton;
}
그리고
- (IBAction)toggleEdit {
BOOL editing = !self.tableView.editing;
self.navigationItem.rightBarButtonItem.enabled = !editing;
if (editing) {
self.navigationItem.leftBarButtonItem.title = NSLocalizedString(@"Done", @"Done");
//Added in the edition for this button has the same color of the UIBarButtonSystemItemDone
self.navigationItem.leftBarButtonItem.style = UIBarButtonItemStyleDone;
}
else{
self.navigationItem.leftBarButtonItem.title = NSLocalizedString(@"Edit", @"Edit");
//Added in the edition for this button has the same color of the UIBarButtonSystemItemDone
self.navigationItem.leftBarButtonItem.style = UIBarButtonItemStylePlain;
}
[self.tableView setEditing:editing animated:YES];
}
그런 다음 당신이 그들 중 하나를 교체 할 필요가 없습니다 toggleEdit 방법.
출처
2010-04-03 13:15:10
wal
아, 그래, 좋아 보인다 시도 할 수 있습니다. 그래도 버튼이 약간 다른 색상 인 곳에서 좋은 "완료"스타일을 얻지는 않는다고 생각합니다. –
스타일이 변경되면이 코드의 DONE 버튼이 UIBarButtonSystemItemDone과 정확히 같습니다. – wal