- (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];
唯一的问题是它打开了该单元格的视图,我需要在最初加载的列表中打开与该名称关联的详细视图。
问题是在我进行搜索时打开相应的详细信息视图
当我进行搜索时,我必须在点击名称时打开详细视图。
答案 0 :(得分:1)
我不是100%确定你在这里遇到什么问题,但要确保在你的委托选择器中检查tableView
参数,以区分搜索结果表视图和初始表视图。 E.g:
[...]
- (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 :(得分: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];
}
}