首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在searchdisplaycontroller中打开详细信息视图

在searchdisplaycontroller中打开详细信息视图
EN

Stack Overflow用户
提问于 2013-01-27 19:17:37
回答 2查看 155关注 0票数 1
代码语言:javascript
复制
- (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 ];
}

代码语言:javascript
复制
 [searchDisplayController setSearchResultsDataSource: self];
 [searchDisplayController setSearchResultsDelegate: self];

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

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

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-01-27 22:09:23

我只会更新Tom的答案:

代码语言:javascript
复制
    - (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];
        }
    }
票数 0
EN

Stack Overflow用户

发布于 2013-01-27 19:31:12

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

代码语言:javascript
复制
[...]
- (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];
    }
}
[...]
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14546798

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档