Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS UISearchController:在取消搜索后等待直到UISearchController被解除_Ios_Objective C_Uitableview_Searchbar_Dispatch Async - Fatal编程技术网

iOS UISearchController:在取消搜索后等待直到UISearchController被解除

iOS UISearchController:在取消搜索后等待直到UISearchController被解除,ios,objective-c,uitableview,searchbar,dispatch-async,Ios,Objective C,Uitableview,Searchbar,Dispatch Async,我有一个UISearchController,当用户单击“取消”按钮时,它将被取消。用户单击cancel按钮后,我希望先取消UISearchController,然后调用showNewTableData方法。下面是我正在使用的代码 - (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar { dispatch_async(dispatch_get_main_queue(), ^{ [self showNew

我有一个
UISearchController
,当用户单击“取消”按钮时,它将被取消。用户单击cancel按钮后,我希望先取消
UISearchController
,然后调用showNewTableData方法。下面是我正在使用的代码

- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar {
    dispatch_async(dispatch_get_main_queue(), ^{
        [self showNewTableData];
    });
}

- (void)showNewTableData {
      if (self.searchController.active && self.searchController.searchBar.text.length > 0) {
         // show search data
      } else {
         // show non search data
      }
    }

使用
dispatch\u async
似乎可以很好地满足我的需求,但不确定这是否是一个好主意。如果我不使用
dispatch\u async
,我将最终显示搜索数据,因为搜索栏尚未完成文本清除,并且仍然处于活动状态。非常感谢您的建议。

鉴于您正在尝试如何进行UI更改,可以在主线程中执行此操作。

因此可以在分派异步块的UITableView中添加新数据,对吗?很抱歉,我只想100%确定。您可以从任何地方添加数据,调度的问题与您的问题有关,因为您希望在下一个问题之前发生一些事情。如果我们专门讨论表视图,最好在搜索开始或结束时更改表视图的数据源,搜索结果和筛选结果,并根据搜索状态进行更改。