(예를 들어, 당신이있는 UITableViewController를 사용하는 경우)에 대응 조치를 변경합니다. 기본적으로 자신의 편집 버튼 항목을 만들고 tableView의 editing
플래그를 사용하여 편집 대 완료를 추적합니다. 케이크 위에 장식하기 위해 테이블에 새 항목을 추가하기 위해 비어있는 경우 "편집"대신 "+"버튼이 표시됩니다.
- (void) updateEditButtonVisibility
{
// tableItems represents the data structure that s
if ([tableItems count] > 0)
{
UIBarButtonSystemItem editButtonType = self.tableView.editing ? UIBarButtonSystemItemDone : UIBarButtonSystemItemEdit;
UIBarButtonItem *editButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:editButtonType
target:self
action:@selector(editButtonTouched)];
self.navigationItem.rightBarButtonItem = editButtonItem;
[editButtonItem release];
}
else
{
UIBarButtonItem *addButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
target:self
action:@selector(addButtonTouched)];
self.navigationItem.rightBarButtonItem = addButtonItem;
[addButtonItem release];
}
}
- (void) editButtonTouched
{
// edit/done button has been touched
[self.tableView setEditing:!self.tableView.editing animated:YES];
[self updateEditButtonVisibility];
}
- (void) addButtonTouched
{
// logic to allow user to add new items goes here
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self updateEditButtonVisibility];
}
프로그래밍 방식으로 뷰를 배치하면 setEditing : animated()도 호출됩니다. 편집 모드. 필자는 편집 모드를 외부 적으로 설정하는 데 사용할 수있는 [super setEditing]을 호출하는 추가 메서드를 추가했습니다. – Symmetric
참고 : 'UITableView' ** 델리게이트 **로 UIViewController를 통해 이것을 수행하는 경우,'UITableView'에 ** 테이블의 ** 편집 상태를'[self.tableView setEditing : 애니메이션 편집 : 애니메이션]. – cloudrave