我有一个TableViewController,一个SearchResultsController和一个WebViewController.当我单击TableViewController中的一个单元格时,它会推动WebViewController打开一个与单元格相关的URL.
TableViewController有一个UISearchController,它将结果过滤到SearchResultsController中,但是当在SearchResultsController中单击一个单元格时,WebViewController不会被推送.
以下是SearchResultsController的didSelectRowAtIndexPath的代码:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { WebViewController *webViewController = [[WebViewController alloc] init]; NSString *extensionURL = (self.searchResults[indexPath.row])[@"url"]; NSURL *baseURL = [NSURL URLWithString:@"http://www.baseurl.com"]; NSURL *URL = [NSURL URLWithString:extensionURL relativeToURL:baseURL]; webViewController.title = (self.searchResults[indexPath.row])[@"title"]; NSLog(@"%@", URL); webViewController.URL = URL; [self.navigationController pushViewController:webViewController animated:YES]; }
我包含了NSLog,看看当单击一个单元格时是否发生了什么,它确实在控制台中显示了url.这让我觉得问题出在navigationController上.
在线查看似乎应该将UISearchController包装在UISearchContainerViewController中,然后将其放入navigationController中.我还是应用程序开发的新手,无法弄清楚如何或在何处执行此操作.
我在我的TableViewController的viewDidLoad中调用我的SearchResultsController,如下所示:
- (void)viewDidLoad { [super viewDidLoad]; SearchResultsViewController *controller = [[SearchResultsViewController alloc] initWithStyle:UITableViewStylePlain]; [self addObserver:controller forKeyPath:@"results" options:NSKeyValueObservingOptionNew context:nil]; self.searchController = [[UISearchController alloc] initWithSearchResultsController: controller]; self.searchController.searchResultsUpdater = self; self.searchController.hidesNavigationBarDuringPresentation = NO; self.searchController.dimsBackgroundDuringPresentation = NO; self.searchController.delegate = self; self.definesPresentationContext = YES; UISearchBar *searchBar = [[UISearchBar alloc] init]; searchBar = self.searchController.searchBar; searchBar.searchBarStyle = UISearchBarStyleMinimal; UITextField *searchField = [searchBar valueForKey:@"_searchField"]; searchBar.barTintColor = [UIColor whiteColor]; searchBar.tintColor = [UIColor whiteColor]; self.navigationItem.titleView = searchBar; }
这是我应该嵌入我的SearchResultsController的地方吗?
在进行搜索时,您将呈现NewModalViewController,因此您需要做的就是在呈现搜索控制器时推送viewcontroller的一些步骤
1)self.definesPresentationContext = YES;
在此之后你应该推动你的viewcontroller
2)[self.presentingViewController.navigationController pushViewController:sec animated:YES];
注意:目前的modalviewcontroller没有导航控制器,所以正常的推送编码不会工作,因为它没有分配给导航.
请享用.....