2011-10-16 2 views
0

이 테이블은 오른쪽 상단에 "편집"이있는 데이터베이스에 연결되어 있습니다. 스 와이프를 삭제할 수 있지만 수정 버튼을 누르면 아무 일도 일어나지 않습니다! 내 말은, 동일한 프로그램에서 다른 테이블에 대한 비슷한 호출을 작성했는데 편집을 누르면 작은 "잠금 해제"가 나타납니다. 그렇다면 그것을 누를 경우 요소/행을 삭제할 수 있습니다 ... 여기에 없습니다!편집 할 때 "삭제 잠금 해제"Subview

- (void)viewDidLoad 
{ 
    self.title = @"Categorie"; 
    [super viewDidLoad]; 
    self.navigationItem.rightBarButtonItem = self.editButtonItem; 
    [self.navigationItem setHidesBackButton:YES animated:YES]; 
    [tableView reloadData]; 
} 

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    return YES; 
} 

- (void)tableView:(UITableView *)_tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if (editingStyle == UITableViewCellEditingStyleDelete) 
    { 
     // A lot of code... 
    } 
} 

답변

1

당신은 setEditing과 편집을 시작 할 수있는 tableView를 알려줄 필요가 : (BOOL) 편집 애니메이션 :

- (void)editTable { 
    if (!self.tableView.editing) [self.tableView setEditing:YES animated:YES]; 
    self.navigationController.rightBarButtonItem = self.doneButton; 
} 

- (void)doneEditing { 
    if (self.tableView.editing) [self.tableView setEditing:NO animated:YES]; 
    self.navigationController.rightBarButtonItem = self.editButton; 
} 
+0

확인 : (BOOL)

다음
//Init your editBarButton UIBarButtonItem *editButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(editTable)]; //Init your doneBarButton UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneEditing)]; 

이 샘플 액션 메소드의 애니메이션 . 이제 작동합니다. 하지만 ii는 편집 모드에있을 때 "편집"대신 "완료"를 표시하지 않습니다. – Oiproks

+0

다른 '완료'barButton이 있어야 편집 버튼으로 전환 할 수 있습니다. 코드를 업데이트하겠습니다. – toddbranch

+0

완벽! 주문서에 코드를 쓰고보기에 입력 할 때 "완료"버튼이 있지만 두 줄의 전환을 해결했습니다. 도와 주셔서 정말로 고맙습니다. – Oiproks

관련 문제