【发布时间】:2018-08-02 17:49:23
【问题描述】:
我有一个UISearchController,当用户单击取消按钮时它会被关闭。用户单击取消按钮后,我希望首先关闭 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_async 似乎可以很好地满足我的要求,但不确定这是否是个好主意。如果我不使用dispatch_async,我最终会显示搜索数据,因为搜索栏还没有完成清除文本并且它仍然处于活动状态。任何建议表示赞赏。
【问题讨论】:
标签: ios objective-c uitableview searchbar dispatch-async