4

그룹화 된 tableView를 관리하는 UITableViewController가 있습니다. tableView는 fetchedResultsController에서 채워집니다. 나는 내비게이션 바에서 편집 버튼을 클릭하면tableView에서 행을 삭제할 때 코어 데이터 오류가 발생했습니다.

, 다음 행을 선택하고 삭제 버튼을 클릭 행이 삭제되고 모든 잘 끝납니다. 나는 행의 삭제 버튼을 공개하고 삭제 버튼을, 다음과 같은 오류와 응용 프로그램 충돌 클릭으로 스 와이프하면

그러나 : 물론

2010-01-06 15:25:18.720 Take10[14415:20b] Serious application error. Exception was caught during Core Data change processing: -[NSCFArray objectAtIndex:]: index (1) beyond bounds (1) with userInfo (null)

2010-01-06 15:25:18.721 Take10[14415:20b] Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSCFArray objectAtIndex:]: index (1) beyond bounds (1)'

을, 오류가 변경 인덱스 번호에 따라 행을 삭제하려고 시도하는 섹션의 행 수 및 삭제 시도 후 테이블 섹션의 나머지 행 수보다 1입니다.

여기 fetchedResultsController에서 데이터를 삭제하려고 시도하는 코드가 있습니다. 같은 방법으로 두 시나리오에 모두 응답하므로 스 와이프 때 충돌이 발생하는 이유를 알 수 없습니다.

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { 

if (editingStyle == UITableViewCellEditingStyleDelete) { 
    // Delete the managed object for the given index path 
    NSManagedObjectContext *context = [fetchedResultsController managedObjectContext]; 
    [context deleteObject:[fetchedResultsController objectAtIndexPath:indexPath]]; 

    // Save the context. 
    NSError *error = nil; 
    if (![context save:&error]) { 
     /* 
     Replace this implementation with code to handle the error appropriately. 

     abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. If it is not possible to recover from the error, display an alert panel that instructs the user to quit the application by pressing the Home button. 
     */ 
     NSLog(@"Unresolved error %@, %@", error, [error userInfo]); 
     abort(); 
    } 
    } 
} 

어떤 아이디어 ??? 삭제 정상 및 슬쩍 사이

감사

JK

+0

controllerDidChangeContent에서 테이블을 다시로드하고 있습니까? – gerry3

+1

objc_exception_throw를 중단하고 예외를 throw하는 메소드를 확인하십시오. 그것은 그것을 추적하는 데 도움이됩니다. –

답변

2

한 가지 차이점은 후자는 tableView:willBeginEditingRowAtIndexPathtableView:didEndEditingRowAtIndexPath를 호출 할 것입니다. 사실 그것은 들여 쓰기를 억제하고 삽입 행을 표시하는 좋은 방법입니다.

또 다른 차이점은 삭제 직후에 setEditing: (매개 변수 값으로 NO)이 호출된다는 것입니다.

정의/재정의 한 세 가지 기능 중 하나에서 중단 점을 설정하고 발생 위치를 좁힐 수 있는지 확인하십시오.

관련 문제