boxmoe_header_banner_img

Hello! 欢迎来到我的博客!

加载中

文章导读

Application tried to present modal view controller on itself Presenting controller is UISearchController


avatar
博主大大 2019年2月17日 5.67k

Overview

近几天在测试公司项目时,遇到一个UISearchController崩溃的问题。

Terminating app due to uncaught exception 'NSInvalidArgumentException', 
reason: 'Application tried to present modal view controller on itself. 
Presenting controller is .'

崩溃的原因

问题似乎是iOS11之后,系统试图恢复firstResponder状态。

解决办法

在关闭视图之前,设置searchController的active为NO,例如:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
   self.searchController.active = NO; // Add this !
   ...

   [self dismissViewControllerAnimated:YES completion:nil];
}

参考资料

iOS UISearchController crash: Application tried to present modal view controller on itself



评论(已关闭)

评论已关闭