关闭UISearchController视图并解除UITableView以访问根视图控制器

时间:2016-08-03 15:48:19

标签: objective-c xcode uitableview uisearchcontroller

上下文:我正在使用ArcGIS Runtime SDK在Objective C中创建一个IOS应用程序。我的根视图控制器是一个地图。我可以选择创建空间书签,并在推到视图上的表视图中查看它们。我在表视图上有一个UISearchController,可以过滤掉书签。如果选择书签而不进行搜索,则会自动平移到该位置。这是通过弹出所有视图控制器,并使用书签变量的标志加载根视图控制器来设置为起始范围来完成的。

我想在searchController表视图中使用相同的功能。

但是,我无法关闭searchController并且书签被缩放,或者搜索控制器被解除,并且用户被带回初始表视图。

到目前为止我所拥有的:

在searchController TableView的didSelectRow方法中:

(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

//Accept the spatial envelope and save it to the shared variable to be passed to main view controller
//Now dismiss the searchController and call method to zoom to bookmark
[self.navigationController dismissViewControllerAnimated:NO completion:^{
     //reference to shared instance method
     [[BookmarksTableViewController sharedBookmark] zoomToBookmark];
}];

在BookmarksTableViewController.m

-(void)zoomToBookmark{
    UIViewController *myController = [self.storyboard instantiateViewControllerWithIdentifier:@"viewController"];
    [self.navigationController pushViewController: myController animated:YES];
    //clear the navigation stack
    self.navigationController.viewControllers = [[NSArray alloc] initWithObjects:myController, nil];
}

对我来说,这似乎应该可行,但所有发生的事情都是UISearchController被解雇,然后表格视图没有被解雇,我回到了我输入搜索文本之前的位置。

关于更好地解雇UISearchController或如何返回我的根视图控制器的想法?

1 个答案:

答案 0 :(得分:0)

希望你的意思是这个答案

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self dismissViewControllerAnimated:NO completion:nil];
}