12

私は異なるセクションのNSFetchedResultControllerがあります。 私はUISearchDisplayControllerを使用して検索しようとすると、クラッシュを持っている:私がチェック2つのセクションで検索するとクラッシュする

*** 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])' 

をし、私の検索配列は、実際に2つのエントリ(期待された結果)があります。

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 

それリターン1

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

は、返信2

面白いことに、セクションが1つだけあれば、完璧に動作します。

お願いします! :)

答えて

38

ないあなたはそれを考え出した場合、私はあなたがやったと思うだろうが、あなたがcellForRowAtIndexPath

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

を使用していると仮定すると

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

もあなたを確認するようにしてくださいself.tableViewを使用しています

+3

この理由を説明できますか?私はそれが将来別の問題を解決するのに役立つかもしれないと思っています。 – Jeremy1026

+9

これは、self.tableViewにセルを要求しているためです。しかし、indexPathは検索時に検索テーブルへのインデックスパスです。インデックスパスはself.tableに対して必ずしも有効ではないので、このインデックスパスを渡すことはできません。 CellIdentifierが検索テーブルに登録されていないため、self.tableにセルの入力を要求する必要があります。 –

+0

はい、それはまだ仕事をするために馬鹿な魔法です! :) –

関連する問題