2011-03-27 6 views
0

내 목록에서 행을 삭제하려고합니다. 그러나 내가 그렇게 할 때마다 프로그램이 중단됩니다.UITableView에서 행 삭제

- (void)tableView:(UITableView *)tv commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { 
    if (editingStyle == UITableViewCellEditingStyleDelete) { 
     [self.logList removeObjectAtIndex:[indexPath row]]; 
     [tv deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; 
    } 
} 

예외 : '잘못된 갱신 : 응용 프로그램을 종료

인해 캐치되지 않는 예외 'NSInternalInconsistencyException ', 이유에 섹션 0의 행 무효 수 행의 수는에 포함 업데이 트 (5) 업데이 트 (5) 후 전에 해당 섹션에 포함 된 행 의 수와 같아야합니다 (5) 플러스 또는 마이너스번호 행의이 섹션에서 삽입 또는 삭제되었습니다 (0 개 삽입, 1 개 삭제됨). '

아무도 올바른 방향으로 나를 가리킬 수 있습니까? datasource-method가 반환하는 행 수를 업데이트해야합니까? 이럴 경우 어떻게해야합니까?

감사합니다. 그런

+0

무엇 당신'를 tableView 않습니다 numberOfRowsInSection :'처럼? – Anomie

답변

0

시도 뭔가 :

- (void)tableView:(UITableView *)tv commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if (editingStyle == UITableViewCellEditingStyleDelete) 
    { 
     [tv beginUpdates]; 
     [tv deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; 

     [self.logList removeObjectAtIndex:[indexPath row]]; 

     [tv endUpdates]; 
    } 
} 
+0

그게 작동하지 않았다 : ( – user676842

+0

당신은 - (NSInteger) tableView : (UITableView *) tableView numberOfRowsInSection : (NSInteger) 섹션 메서드에 넣었습니까? – klefevre

+0

나는 아무것도 쓰지 않아도 1을 작성해야합니까? – user676842