今天遇到一个问题
在 tableview
的 didSelectRowAtIndexPath:
调用 dismissViewControllerAnimated
时候,发现有明显的延迟
如果双击的话则立即dismiss
2019-01-07 16:32:49.154877+0800 FF[1163:304337] ----->
2019-01-07 16:32:54.452650+0800 FF[1163:304337] ----->
在 didSelectRowAtIndexPath:
断点验证是否是在主线程,结果确实是在主线程
(lldb) po [NSThread isMainThread]
0x0000000000000001
(lldb) po [NSThread currentThread]
<NSThread: 0x2822934c0>{number = 1, name = main}
(lldb)
解决方法1
如下
重新把 dismissViewControllerAnimated:
添加到主线程
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
dispatch_async(dispatch_get_main_queue(), ^{
[self dismissViewControllerAnimated:YES completion:^(){
}];
});
}
2019-01-07 16:39:29.985855+0800 FF[1167:305510] ----->
2019-01-07 16:39:30.493599+0800 FF[1167:305510] ----->
解决方法2
如下
首先调用 deselectRowAtIndexPath:animated:
不要动画
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:NO];
[self dismissViewControllerAnimated:YES completion:^(){
}];
}
因此,小心谨慎地推测,tableview
可能有小问题
一脸懵逼
不定期更新 不合适的地方 还请指点~ 感激不尽