6

プロジェクトの検索バーを実装しています。検索部分は大丈夫です。生データを表示し、検索テキストでデータをフィルタリングできます。検索結果のtableViewのセルをタップしても詳細ビューに遷移しませんでした。しかし、生データについては、詳細ビューに移行できます。ストーリーボードを使用しているので、このprepareForSegue方法を使用します。これまでのコードは次のとおりです。

- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{

    if ([segue.identifier isEqualToString: @"Book Detail Segue"]) {

    BookDetailsTVC *bookDetailsTVC = segue.destinationViewController; // for the detail view controller
    bookDetailsTVC.delegate = self;

    if (self.tableView == self.searchDisplayController.searchResultsTableView) { // The if block is not working
        NSLog(@"Search Display Controller");
        bookDetailsTVC.book = [self.searchResults objectAtIndex: self.searchDisplayController.searchResultsTableView.indexPathForSelectedRow.row];
    } else {
        NSLog(@"Default Display Controller");
        NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
        bookDetailsTVC.book = [self.objects objectAtIndex: indexPath.row];
    }
}
}

メソッドを使ってみたところdidSelectRowAtIndexPath、詳細ビューに遷移できました。しかし、次のようなエラーメッセージが表示されました:

  • Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get corrupted.

  • Unbalanced calls to begin/end appearance transitions for <BookDetailsTVC: 0x69b5300>.

didSelectRowAtIndexPath のコードは次のとおりです。

- (void) tableView: (UITableView *) tableView didSelectRowAtIndexPath: (NSIndexPath *) indexPath
{
    BookDetailsTVC *bookDetailsTVC = [[BookDetailsTVC alloc] init];

    if (tableView == self.searchDisplayController.searchResultsTableView) {

    bookDetailsTVC.book = [self.searchResults objectAtIndex: self.searchDisplayController.searchResultsTableView.indexPathForSelectedRow.row];

    [self performSegueWithIdentifier: @"Book Detail Segue" sender:self];

    NSLog(@"Search Display Controller");
} else {

    bookDetailsTVC.book = [self.objects objectAtIndex: indexPath.row];

    [self performSegueWithIdentifier: @"Book Detail Segue" sender: self];

    NSLog(@"Default Display Controller");
}
}

手伝ってくれてありがとう。

4

2 に答える 2

20

問題は解決しました, cellForRowAtIndexPath でこれを変更します

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: CellIdentifier];

UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier: CellIdentifier];

prepareForSegue メソッドでは、self.searchDisplayController.active を使用して現在のテーブルビューを確認できます。

if (self.searchDisplayController.active) {
    NSLog(@"Search Display Controller");
    bookDetailsTVC.book = [self.searchResults objectAtIndex: self.searchDisplayController.searchResultsTableView.indexPathForSelectedRow.row];
} else {
    NSLog(@"Default Display Controller");
    bookDetailsTVC.book = [self.objects objectAtIndex: self.tableView.indexPathForSelectedRow.row];
}
于 2012-08-05T23:46:36.007 に答える
1
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView == self.searchDisplayController.searchResultsTableView) {

        self.selectedPerson = [self.searchResults objectAtIndex:indexPath.row];

        PersonasDetalle *pd = [self.storyboard instantiateViewControllerWithIdentifier:@"PersonaDetalle"];
        pd.persona = self.selectedPerson;

        [self.navigationController pushViewController:pd animated:YES];

    }
}
于 2012-09-15T09:54:57.367 に答える