Num*_*riq 40 iphone objective-c modalviewcontroller ios
我有一个基于标签栏的应用程序.所有5个选项卡中都有导航控制器,自定义视图控制器实例正确设置为根视图控制器.加载就好了.其中一些视图控制器包含表视图.我想在用户在表视图中选择一行时向用户显示模态视图控制器.didSelectRowAtIndexPath委托方法的(相关部分)如下所示:
SampleSelectorViewController *sampleVC = [[SampleSelectorViewController alloc] init];
[self presentViewController:sampleVC animated:YES completion:NULL];
Run Code Online (Sandbox Code Playgroud)
模态视图控制器出现但是在非常明显的延迟之后出现.有时它甚至要求用户第二次点击该行.我已经验证过的一些事情是:
有什么想法/建议吗?
azs*_*mej 56
似乎presentViewController:animated:completion从内部呼唤tableView:didSelectRowAtIndexPath:是有问题的.在仪器中使用Time Profiler时也很难找到任何突出的东西.有时我的模态视图会在不到一秒的时间内出现,有时则需要4s甚至9s.
我认为这与底层UIPresentationController和布局有关,这是我在选择时间区域和选择时间分析器中的模态演示之间选择时间区域时所看到的少数几项内容之一.
雷达存在描述此问题:http://openradar.appspot.com/19563577
解决方法很简单但不满意:稍微延迟演示,以避免引起减速的任何争议行为.
dispatch_async(dispatch_get_main_queue(), ^{
[self presentViewController:nav animated:YES completion:nil];
});
Run Code Online (Sandbox Code Playgroud)
Swift 4:您可以使用如下。
DispatchQueue.main.async {
let popUpVc = Utilities.viewController(name: "TwoBtnPopUpViewController", onStoryboard: "Login") as? TwoBtnPopUpViewController
self.present(popUpVc!, animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)
这个对我有用。
如果在tableView(:didSelectRowAt :)中调用present(:animated:completion :),selectionStyle == .none对于选定的tableview单元格,则您会遇到这种奇怪的行为,然后尝试在之前调用tableView.deselectRow(at:animated :) tableView(_:didSelectRowAt :)中的任何操作。
有帮助吗?
小智 5
我猜您还将单元格的 selectionStyle 设置为UITableViewCellSelectionStyleNone. 我改为UITableViewCellSelectionStyleDefault,它工作完美。
| 归档时间: |
|
| 查看次数: |
8378 次 |
| 最近记录: |