12

다른 섹션이있는 NSFetchedResultController이 있습니다. 내가 UISearchDisplayController를 사용하여 검색 할 때 나는 충돌이 : 나는 확인두 섹션에서 검색 할 때 크래시가 발생했습니다.

*** Assertion failure in -[UITableViewRowData rectForRow:inSection:], /SourceCache/UIKit/UIKit-2372/UITableViewRowData.m:1630 

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'request for rect at invalid index path (<NSIndexPath 0x1d2c4120> 2 indexes [0, 1])' 

을 내 검색 배열은 실제로 두 개의 항목 (예상 된 결과)가 있습니다

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 

그것은 반환 한

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 

은 2를 반환합니다.

재미있는 점은 하나의 섹션 만 있으면 완벽하게 작동한다는 것입니다.

도와주세요. :)

답변

38

당신이 그것을 알아 낸 경우에, 나는 당신이 한 생각하지만, 가정 당신은 또한 확인

if (tableView == self.searchDisplayController.searchResultsTableView) { 
    cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
} else { 
    cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; 
} 

을 당신의 cellForRowAtIndexPath에

[self.tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; 

를 사용하고 있는지 확인하지 당신 self.tableView를 사용 중입니다

+3

이유를 설명해 주시겠습니까? 앞으로도 다른 문제를 해결하는 데 도움이 될지 궁금합니다. – Jeremy1026

+9

셀에 대해 self.tableView를 요청하고 있기 때문입니다. 그러나 indexPath는 검색 할 때 검색 테이블에 대한 인덱스 경로입니다. 인덱스 경로는 self.table에 반드시 유효하지 않으므로이 인덱스 경로를 전달할 수 없습니다. CellIdentifier가 검색 테이블에 등록되지 않았으므로 self.table에 셀을 요청해야합니다. –

+0

그리고 네, 여전히 일을하게하는 것은 어리석은 마술입니다! :) –