0

私はsearchDisplayControllerでテーブルビューを持っています。テキストを検索すると、結果が画面に正常に表示されます。私の問題は、既存の結果にセルを追加したいときに発生します。セルの追加は、searchDisplayController がアクティブなときに行う必要があります。

あれは:

    -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
        NSMutableDictionary * dict ;
        BOOL isSearchView = tableView == self.searchDisplayController.searchResultsTableView;
        if (isSearchView) {
            dict = [searchTasks objectAtIndex:indexPath.row];
            [self.searchDisplayController.searchResultsTableView deselectRowAtIndexPath:indexPath
                                                                               animated:YES];
        }
        else{
            dict = [self.tasks objectAtIndex:indexPath.row];
            [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
        }
            Task * task = [self getsomeTask];
            NSIndexPath *  ip = [NSIndexPath indexPathForRow:indexPath.row+1  
inSection:indexPath.section];
            if (isSearchView) {
                [searchTasks insertObject:task atIndex:ip.row];
                [self.searchDisplayController.searchResultsTableView  
                                        insertRowsAtIndexPaths:@[ip]
                                        withRowAnimation:UITableViewRowAnimationRight];

    }

これが実行された後、最後の行の後insertRowsAtIndexPaths:@[ip]

コードが実行されます。

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (self.searchDisplayController.isActive) {
        return [searchTasks count];
    } else {
        return [tasks count];
    }
}

これは問題ありません。ここでは、プログラム ロジックに従って true である最初のオプションを選択します。しかし、それはクラッシュし、この実行後は決して呼び出されません

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

UITableviewのデリゲート機能。

そして私にエラーを与えます:

*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 1 beyond bounds [0 .. 0]'

rowcount 関数の後に cellForRowAtIndexPath 関数を呼び出さない理由がわかりません。

助言がありますか?

4

0 に答える 0