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

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

博主大大

假如生活欺骗了你,不要悲伤,不要难过,反正明天也一样......

留下你的评论

*评论支持代码高亮<pre class="prettyprint linenums">代码</pre>

猜你喜欢