1
- (void)viewDidLoad {
    [super viewDidLoad];

    searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 160, 44)];
    searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self];

    searchDisplayController.delegate = self;
    searchDisplayController.searchResultsDataSource = self;

    self.tableView.tableHeaderView = searchBar;

    [searchDisplayController setSearchResultsDataSource: self];
    [searchDisplayController setSearchResultsDelegate: self];![enter image description here][2]


    // Do any additional setup after loading the view, typically from a nib.
    self.navigationItem.leftBarButtonItem = self.editButtonItem;

    UIBarButtonItem *addButton = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(insertNewObject:)] autorelease];
    self.navigationItem.rightBarButtonItem = addButton;

    // inizializziamo l'oggetto Data
    _objects = [[Data alloc] init];

    filteredlist=[[NSMutableArray alloc]initWithArray:_objects.lista ];
}

在这个方法中,我添加了打开详细视图

 [searchDisplayController setSearchResultsDataSource: self];
 [searchDisplayController setSearchResultsDelegate: self];

唯一的问题是它打开了该单元格的视图,我需要在最初加载的列表中打开与该名称关联的详细视图。

问题是我搜索的时候打开对应的detail view

当我进行搜索时,我必须在单击名称时打开详细视图。

4

2 回答 2

1

我不是 100% 确定您在这里有什么问题,但请确保在您的委托选择器中检查tableView参数以区分您的搜索结果表视图和初始表视图。例如:

[...]
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (tableView == self.tableView) {
        // ...do your tableView stuff
    } else if (tableView == searchDisplayController.searchResultsTableView) {
        id someSearchResultObject = [_filteredlist objectAtIndex:indexPath.row];
        SomeDetailViewController *vc = [[SomeDetailViewController alloc] initWithSearchResult:someSearchResultObject];
        [self.navigationController pushViewController:vc animated:YES];
        [vc release];
    }
}
[...]
于 2013-01-27T11:31:12.260 回答
0

我将更新汤姆的答案:

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
        if (tableView == self.tableView) {
            // ...do your tableView stuff
        } else if (tableView == searchDisplayController.searchResultsTableView) {
            DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"detailViewController" bundle:nil];
[self.navigationController pushViewController:detailViewController animated:YES];
        }
    }
于 2013-01-27T14:09:23.393 回答