2017-05-11 1 views
0

문제점이 무엇인지 잘 모르겠습니다. 치명적인 예외 : 오류는 여기에서 발생UITableView 새로 표시되는 행에 대해 누락 된 셀이 있습니다. NSInternalInconsistencyException

Fatal Exception: NSInternalInconsistencyException 
0 CoreFoundation     0x191bbefd8 __exceptionPreprocess 
1 libobjc.A.dylib    0x190620538 objc_exception_throw 
2 CoreFoundation     0x191bbeeac +[NSException raise:format:] 
3 Foundation      0x192656710 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] 
4 UIKit       0x198022b3c __46-[UITableView _updateWithItems:updateSupport:]_block_invoke.1049 
5 UIKit       0x197d234b8 +[UIView(UIViewAnimationWithBlocks) _setupAnimationWithDuration:delay:view:options:factory:animations:start:animationStateGenerator:completion:] 
6 UIKit       0x197d39bac +[UIView(UIViewAnimationWithBlocks) animateWithDuration:delay:options:animations:completion:] 
7 UIKit       0x197ee8770 -[UITableView _updateWithItems:updateSupport:] 
8 UIKit       0x197eccfbc -[UITableView _endCellAnimationsWithContext:] 
9 MyApp      0x1000ed518 -[UICommentsTableViewController insertNewComment:atLocation:] (UICommentsTableViewController.m:1228) 
10 MyApp      0x1000e99e8 -[UICommentsTableViewController onCommentsReceivedWithMessage:] (UICommentsTableViewController.m:881) 
11 MyApp      0x1000e9094 -[UICommentsTableViewController processWSMessage:] (UICommentsTableViewController.m:803) 
12 MyApp      0x1000e8f84 -[UICommentsTableViewController webSocket:didReceiveMessage:] (UICommentsTableViewController.m:788) 
13 MyApp      0x10009ea30 __30-[SRWebSocket _handleMessage:]_block_invoke (SRWebSocket.m:837) 
14 libdispatch.dylib    0x190a769e0 _dispatch_call_block_and_release 
15 libdispatch.dylib    0x190a769a0 _dispatch_client_callout 
16 libdispatch.dylib    0x190a7b5e8 _dispatch_main_queue_callback_4CF 
17 CoreFoundation     0x191b6d0c0 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ 
18 CoreFoundation     0x191b6acdc __CFRunLoopRun 
19 CoreFoundation     0x191a9ad94 CFRunLoopRunSpecific 
20 GraphicsServices    0x193504074 GSEventRunModal 
21 UIKit       0x197d53130 UIApplicationMain 
22 MyApp      0x10011ba40 main (main.m:7) 
23 libdyld.dylib     0x190aa959c start 

: NSInternalInconsistencyException 새로 가시의 행 (78)

여기에 스택 추적의 대한 셀을 누락

- (void)insertNewComment:(NSIndexSet *)indexSet atLocation:(NSInteger)location{ 

    [self.tableView beginUpdates]; 

    NSMutableArray *indexArray = [NSMutableArray new]; 
    if (!indexSet) { 
     [indexArray addObject:[NSIndexPath indexPathForRow:location inSection:0]]; 
    } else { 
     [indexSet enumerateIndexesUsingBlock:^(NSUInteger index, BOOL *stop) { 
      [indexArray addObject:[NSIndexPath indexPathForRow:index inSection:0]]; 
     }]; 
    } 

    [self.tableView insertRowsAtIndexPaths:indexArray withRowAnimation:UITableViewRowAnimationBottom]; 
    [self.tableView endUpdates]; 

} 

나는 셀에 대해 자동 레이아웃을 사용하고는, 높이를 수동으로 계산하고 장치 방향에 따라 캐시했습니다.

높이 계산기 :

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { 


    Comment* comment = self.comments[indexPath.row]; 

    CGFloat cellHeight = [self getHeightForLayoutMode:self.screenMode forCommentID:comment.commentID]; 

    if(cellHeight > 0) { 

     return cellHeight; 
    } 


    if([comment isType2]) { 
     [self setHeightForLayoutMode:self.screenMode forCommentID:comment.commentID height:106]; 
     return 106; 
    } 

    CGFloat width = tableView.bounds.size.width - 100; 

    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle defaultParagraphStyle] mutableCopy]; 
    paragraphStyle.lineBreakMode = NSLineBreakByWordWrapping; 


    NSDictionary *attributes = @{NSFontAttributeName: [UIFont fontWithName:@"MyFont" size:11.0f], NSParagraphStyleAttributeName:paragraphStyle}; 

    CGRect rect = [comment.message boundingRectWithSize:CGSizeMake(width, CGFLOAT_MAX) 
               options:NSStringDrawingUsesLineFragmentOrigin 
              attributes:attributes 
               context:nil]; 

    CGFloat height = 31+ceilf(rect.size.height); 

    [self setHeightForLayoutMode:self.streamViewController.screenMode forCommentID:comment.commentID height:height]; 

    return height; 
} 

사람이 (Crash with Missing cell for newly visible row when updating UITableView) 등의 문제가 있고, 그들은 단지 estimatedSectionHeaderHeight을 제거,하지만 난 내 코드에 estimatedSectionHeaderHeight이 없습니다.

답변

0

이 오류는 값을 삽입 할 때 섹션 수가 범위를 벗어날 때 발생합니다. 높이 문제는 아니에요.

+0

흠 나는 1 섹션 만 있기 때문에 이상합니다. [indexArray addObject : [NSIndexPath indexPathForRow : 위치 inSection : 0]]; – ordinaryman09

+0

또한 크래시 전에 로그를 둡니다. 다음과 같습니다. \t begin insertNewComment location is : 773, comment count is 774 그래서 self.comments.count는 774이고 인덱스 773에 삽입합니다. 또한 모든 장치에서 충돌이 발생하지만 대부분의 충돌 (85 %)은 iPhone 5, 5s, SE에서 발생합니다. – ordinaryman09

0

문제의 원인을 파악했습니다.

내보기 컨트롤러 내에 키보드가 표시되도록하는 텍스트 뷰가 있습니다. UITableView를 맨 아래에 고정 시켰습니다. keyboardWillShow에서 scrollToBottom으로 설정합니다. & 텍스트 뷰 높이가 변경 될 때 삽입을 조정합니다. 키보드가 나타나면 tableview가 거의 보이지 않습니다 (특히 iPhone 5에서).

지금 수정 내가있는 tableview의 같은 높이 & 가시성을 유지하면서 텍스트 뷰의 상단에있는 tableview의 바닥을 고정하고, 나는 자동 레이아웃이 돌봐 때문에, 더 이상 인세 조정 scrollToBottom & 필요가 없습니다 . 희망은 누군가를 돕는다!

건배.

관련 문제