행 삭제 : '잘못된 업데이트 : 섹션 0의 행 수가 잘못되었습니다'오류

Eloy

11-24-2013 : 좀 더 디버깅을했는데 removeProject가 잘 작동한다는 것을 알게되었습니다. (제거 전후의 모든 프로젝트를 인쇄했습니다)-(NSInteger) tableView : (UITableView *) tableView numberOfRowsInSection : (NSInteger) 섹션으로 돌아올 때만 카운트는 (total-1) 대신 0입니다.

============

나는 잠시 동안이 오류에 갇혀 있습니다. Core Data를 더 잘 이해하기 위해 고객과 그의 프로젝트를 입력 할 수있는이 테스트 프로젝트를 만들었습니다. 프로젝트는 클라이언트와 관련이 있습니다. 프로젝트의 경우 클라이언트의 ViewController를 복사하고 약간의 변경을 수행했습니다. 여러 클라이언트를 입력 한 후 삭제할 수 있습니다. 관련 프로젝트를 삭제하고 싶을 때 문제가 시작됩니다. 프로젝트가 하나 뿐인 클라이언트가있는 경우 오류없이 삭제할 수 있습니다. 클라이언트에 두 개 이상의 프로젝트가있는 경우이 클라이언트에서 프로젝트를 삭제할 수 없습니다. 삭제하면이 오류가 발생합니다.

2013-10-30 10:00:23.145 [6160:70b] *** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-2903.2/UITableView.m:1330
2013-10-30 10:00:23.147 [6160:70b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0.  The number of rows contained in an existing section after the update (0) must be equal to the number of rows contained in that section before the update (2), plus or minus the number of rows inserted or deleted from that section (0 inserted, 1 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).'
*** First throw call stack:
(

 .....
     )
     libc++abi.dylib: terminating with uncaught exception of type NSException
     Program ended with exit code: 0 

이 사이트에서 많은 답변을 읽은 후 numberOfRowsInSection 메서드에서 코드를 변경해야한다고 생각하지만 변경해야 할 내용이 표시되지 않습니다.

내 코드 :

Datastore를 만들었습니다.

DataStore.m

    #import "BITDataStore.h"
    #import "Client.h"
    #import "Project.h"

    @implementation DataStore


+ (BITDataStore *)sharedStore
{
    static BITDataStore *sharedStore = nil;
    if (!sharedStore) 
        sharedStore = [[super allocWithZone:nil]init];

        return sharedStore;
}    

-(void)removeClient:(Client *)client
{
    // remove from NSManagedObjectContext
    [context deleteObject:client];

    // remove from allClients array
    [allClients removeObjectIdenticalTo:client];
    NSLog(@"remove client");
}

-(void)removeProject:(Project *)project
{
    // remove from NSManagedObjectContext
    [context deleteObject:project];

    // remove from allProjects array
    [allProjects removeObjectIdenticalTo:project];

    // remove from relatedProjects array 
    [relatedProjects removeObjectIdenticalTo:project];
    NSLog(@"remove project %@", [project project]);

}


-(NSArray *)relatedProjects:(Client *)client;
{
    NSFetchRequest *request = [[NSFetchRequest alloc]init];

    NSEntityDescription *e = [[model entitiesByName] objectForKey:@"Project"];

    [request setEntity:e];

    // Check if client is related to Project
    [request setPredicate: [NSPredicate predicateWithFormat:@"clients == %@", client.objectID]];

    NSSortDescriptor *sd = [NSSortDescriptor sortDescriptorWithKey:@"project"
                                                         ascending:YES];
    [request setSortDescriptors:[NSArray arrayWithObject:sd]];

    NSError *error;
    NSArray *result = [context executeFetchRequest:request error:&error];

    if (!result) {
        [NSException raise:@"Fetch failed"
                    format:@"Reason: %@", [error localizedDescription]];
    }
    relatedProjects = [[NSMutableArray alloc] initWithArray:result];

    return relatedProjects;
}   
@end

ProjectDataViewController.m

@synthesize client, project;


-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [[self tableView] reloadData];
}


#pragma mark - Table view data source

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [[[BITDataStore sharedStore]relatedProjects:client]count];        
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    // Configure the cell...
    if (cell == nil){
        cell = [[UITableViewCell alloc]
                initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
    }

   Project *p = [[[BITDataStore sharedStore]relatedProjects:client]
                                              objectAtIndex:[indexPath row]];

    [[cell textLabel] setText:[p project]];

    return cell;
}

// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        BITDataStore *ds = [BITDataStore sharedStore];
        NSArray *selectedProjects = [ds relatedProjects:client];

        Project *pr = [selectedProjects objectAtIndex:[indexPath row]];
        NSLog(@"Deleting project %@", [pr project]);
       [ds removeProject:pr];

        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
        // Finally, reload data in view
        [[self tableView] reloadData];
        NSLog(@"Reload data"); 
    }   
    else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}

@end

정보가 충분하기를 바랍니다. 그렇지 않은 경우 알려 주시기 바랍니다.

Eloy

내 삭제 규칙을 계단식에서 무효화로 변경했고 작동했습니다.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

NSInternalInconsistencyException 이유 : '잘못된 업데이트 : 섹션 0의 잘못된 행 수'

분류에서Dev

제공된 행 이름의 길이가 R에서 잘못되었습니다.

분류에서Dev

홈에서 사용자 폴더가 삭제되었습니다. 잘못 구성된 fstab이이 작업을 수행 할 수 있습니까? (해결됨, fstab의 subvol 옵션으로 가능한 문제)

분류에서Dev

섹션 0의 잘못된 행 수를 나타내는 tableview 셀 추가

분류에서Dev

Rand (Checksum (Newid ())) 사용시 업데이트 된 행 수가 잘못되었습니다.

분류에서Dev

dtype이 잘못된 오류 행과 열을 동시에 삭제

분류에서Dev

Airflow의 xcom 변수 제거가 작동 오류와 함께 작동하지 않습니다. "1 행의 'execution_date'에 잘못된 datetime 값이 있습니다."

분류에서Dev

Dispatch.main.async 섹션의 잘못된 행 수

분류에서Dev

XML 오류, '루트 수준의 데이터가 잘못되었습니다.'

분류에서Dev

SoapUI 테스트 실행에서 "디렉터리 이름이 잘못되었습니다."오류가 반환 됨

분류에서Dev

오류 : 토큰의 구문 오류, 패키지 선언 섹션의 구성이 잘못되었습니다.

분류에서Dev

행렬의 마지막 숫자가 잘못되었습니다.

분류에서Dev

로그인 이벤트 리스너의 다른 트랜잭션 오류로 인해 행이 업데이트 또는 삭제 되었습니까?

분류에서Dev

명확하지 않은 이유로이 오류를 제공하는 항목 별 환경 : 무언가 잘못되었습니다. \ item (11 행에서 발생)

분류에서Dev

OSX 수정 Selenium Chromedriver 실행 오류 생성 알 수없는 시스템 오류 -86 실행 파일의 CPU 유형이 잘못 되었습니까?

분류에서Dev

[mntent] : / etc / fstab의 16 행이 잘못되었습니다.

분류에서Dev

치명적인 오류 : 상수 표현식에 5 행의 /PATH/initClass.php에 잘못된 작업이 포함되어 있습니다.

분류에서Dev

"--retry"로 오이를 실행할 때 "잘못된 옵션"오류

분류에서Dev

루트 수준의 데이터가 잘못되었습니다. 1 행, 위치 1입니다. XML이 유효하지 않습니다.

분류에서Dev

Sleep ()이 "잘못된"순서로 실행되었습니다.

분류에서Dev

경고 : 79 행의 /app/design/adminhtml/default/default/template/canonical/canonical/edit/tab/header.phtml에서 foreach ()에 대해 잘못된 인수가 제공되었습니다.

분류에서Dev

C ++ 연결 Excel 오류 : "수식에 사용 된 값의 데이터 형식이 잘못되었습니다."

분류에서Dev

fromJSON + ldply : 행렬의 잘못된 첨자 개수 오류 수정

분류에서Dev

DatabaseError : 잘못된 수의 바인딩이 제공되었습니다.

분류에서Dev

Netsuite ODBC 오류 : pyodbc 실행에서`[HY000] 디렉터리 이름이 잘못되었습니다. '오류가 발생합니다.

분류에서Dev

실행시 저장 프로 시저가 오류를 발생 시키는데 오류가 표시된 잘못된 구문이 표시되지 않습니다.

분류에서Dev

행렬의 잘못된 첨자 개수 오류

분류에서Dev

업데이트 전에 2 개의 행만 포함 된 섹션 1에서 행 2를 삭제하려고합니다.

분류에서Dev

오류 : 크기가 0 인 배열이 잘못되었습니다.

Related 관련 기사

  1. 1

    NSInternalInconsistencyException 이유 : '잘못된 업데이트 : 섹션 0의 잘못된 행 수'

  2. 2

    제공된 행 이름의 길이가 R에서 잘못되었습니다.

  3. 3

    홈에서 사용자 폴더가 삭제되었습니다. 잘못 구성된 fstab이이 작업을 수행 할 수 있습니까? (해결됨, fstab의 subvol 옵션으로 가능한 문제)

  4. 4

    섹션 0의 잘못된 행 수를 나타내는 tableview 셀 추가

  5. 5

    Rand (Checksum (Newid ())) 사용시 업데이트 된 행 수가 잘못되었습니다.

  6. 6

    dtype이 잘못된 오류 행과 열을 동시에 삭제

  7. 7

    Airflow의 xcom 변수 제거가 작동 오류와 함께 작동하지 않습니다. "1 행의 'execution_date'에 잘못된 datetime 값이 있습니다."

  8. 8

    Dispatch.main.async 섹션의 잘못된 행 수

  9. 9

    XML 오류, '루트 수준의 데이터가 잘못되었습니다.'

  10. 10

    SoapUI 테스트 실행에서 "디렉터리 이름이 잘못되었습니다."오류가 반환 됨

  11. 11

    오류 : 토큰의 구문 오류, 패키지 선언 섹션의 구성이 잘못되었습니다.

  12. 12

    행렬의 마지막 숫자가 잘못되었습니다.

  13. 13

    로그인 이벤트 리스너의 다른 트랜잭션 오류로 인해 행이 업데이트 또는 삭제 되었습니까?

  14. 14

    명확하지 않은 이유로이 오류를 제공하는 항목 별 환경 : 무언가 잘못되었습니다. \ item (11 행에서 발생)

  15. 15

    OSX 수정 Selenium Chromedriver 실행 오류 생성 알 수없는 시스템 오류 -86 실행 파일의 CPU 유형이 잘못 되었습니까?

  16. 16

    [mntent] : / etc / fstab의 16 행이 잘못되었습니다.

  17. 17

    치명적인 오류 : 상수 표현식에 5 행의 /PATH/initClass.php에 잘못된 작업이 포함되어 있습니다.

  18. 18

    "--retry"로 오이를 실행할 때 "잘못된 옵션"오류

  19. 19

    루트 수준의 데이터가 잘못되었습니다. 1 행, 위치 1입니다. XML이 유효하지 않습니다.

  20. 20

    Sleep ()이 "잘못된"순서로 실행되었습니다.

  21. 21

    경고 : 79 행의 /app/design/adminhtml/default/default/template/canonical/canonical/edit/tab/header.phtml에서 foreach ()에 대해 잘못된 인수가 제공되었습니다.

  22. 22

    C ++ 연결 Excel 오류 : "수식에 사용 된 값의 데이터 형식이 잘못되었습니다."

  23. 23

    fromJSON + ldply : 행렬의 잘못된 첨자 개수 오류 수정

  24. 24

    DatabaseError : 잘못된 수의 바인딩이 제공되었습니다.

  25. 25

    Netsuite ODBC 오류 : pyodbc 실행에서`[HY000] 디렉터리 이름이 잘못되었습니다. '오류가 발생합니다.

  26. 26

    실행시 저장 프로 시저가 오류를 발생 시키는데 오류가 표시된 잘못된 구문이 표시되지 않습니다.

  27. 27

    행렬의 잘못된 첨자 개수 오류

  28. 28

    업데이트 전에 2 개의 행만 포함 된 섹션 1에서 행 2를 삭제하려고합니다.

  29. 29

    오류 : 크기가 0 인 배열이 잘못되었습니다.

뜨겁다태그

보관