- (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];唯一的问题是它会打开该单元格的视图,而我需要在最初加载的列表中打开与该名称相关联的详细视图。
当我执行搜索时,我必须在单击名称时打开详细信息视图。
发布于 2013-01-27 22:09:23
我只会更新Tom的答案:
- (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-27 19:31:12
我不能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];
}
}
[...]https://stackoverflow.com/questions/14546798
复制相似问题