Objective c 在searchdisplaycontroller中打开详细视图

Objective c 在searchdisplaycontroller中打开详细视图,objective-c,Objective C,在这个方法中,我添加了打开细节视图的功能 - (void)viewDidLoad { [super viewDidLoad]; searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 160, 44)]; searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsC

在这个方法中,我添加了打开细节视图的功能

- (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 ];
}
唯一的问题是,它会打开该单元格的视图,而我需要在最初加载的列表中打开与该名称关联的详细视图

问题是在执行搜索时打开相应的详细视图


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

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

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

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

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

我将更新Tom的答案:

[...]
- (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];
    }
}
[...]

我将更新Tom的答案:

[...]
- (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];
    }
}
[...]

不,这已经完成了。问题是在执行以下操作时打开相应的详图视图:search@user1949260你使用XIB还是故事板?也许你应该澄清你的问题。我不知道你所说的“搜索时打开相应的详细视图”是什么意思。搜索时,我必须在单击名称时打开详细视图。不,这已经完成。问题是在执行以下操作时打开相应的详图视图:search@user1949260你使用XIB还是故事板?也许你应该澄清你的问题。我不知道你所说的“搜索时打开相应的详细视图”是什么意思。搜索时,我必须在单击名称时打开详细视图。@FlinkDo不使用情节提要不工作DetailViewController*DetailViewController=[[DetailViewController alloc]initWithNibName:@“DetailViewController”bundle:nil];[self.navigationController pushViewController:detailViewController动画:是]@用户1949260,因为您应该将DetailViewController更改为您的DetailViewController名称。您是否在initWithNibName:@“.”中更改了文件名?@FlinkDo不使用情节提要DetailViewController*DetailViewController=[[DetailViewController alloc]initWithNibName:@“DetailViewController”捆绑包:nil];[self.navigationController pushViewController:detailViewController动画:是]@用户1949260,因为您应该将DetailViewController更改为您的DetailViewController名称。您是否在initWithNibName中更改了文件名:@“。”?