UITableView和presentViewController需要2次点击才能显示 [英] UITableView and presentViewController takes 2 clicks to display

查看:399
本文介绍了UITableView和presentViewController需要2次点击才能显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用UITableView来呈现各种viewControllers。根据单击的索引,它将显示一个不同的视图控制器,然后可以将其解除。由于某种原因,我的一个ViewControllers需要两次点击才能显示。因此,似乎每个其他点击都有效。其他视图演示工作正常,所以表格可能还可以。

I am using a UITableView to present a variety of viewControllers. Depending on which index is clicked, it will present a different view controller, which can then be dismissed. For some reason one of my ViewControllers takes two clicks to display. Thus, it seems every other click is working. Other view presentations work okay, so the table is probably okay.

我在ViewController中看到的即将显示的是第一次点击,它通过didSelectRowAtIndexPath然后在目标视图中触发:ViewWillLoad,ViewLoaded,ViewWillAppear ....但不是ViewDidAppear。在第二次单击时,只有ViewDidAppear会在显示时触发。在第二次单击时,它甚至没有通过didSelectRowAtIndexPath。此外,我可以第二次点击屏幕上的任意位置,它会显示。

What I see in the ViewController about to be displayed is that on the first click, it makes it through didSelectRowAtIndexPath and then fires in the target view: ViewWillLoad, ViewLoaded, ViewWillAppear.... but not ViewDidAppear. On the second click, only ViewDidAppear will fire as it displays. On the second click it doesn't even go through didSelectRowAtIndexPath. Also, I can click anywhere on the screen on the second time and it will display.

它将继续来回执行此操作,似乎每次只显示目标视图其他点击。有没有想过为什么会这样?

It will continue to do this back and forth, seemingly only displaying the target view every other click. Any thoughts why this is occuring?

/* RightPanelViewController */
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
switch(indexPath.row){
    case 0:
        // this view takes two clicks to display
        [self presentViewController:self.delegateRef.savedRidesViewController animated:YES completion:nil];
        break;
    case 1:
        // this works fine, as do others
        [self presentViewController:self.delegateRef.sensorsViewController animated:YES completion:nil];
        break;
    case 2:
       ...
}

/* savedRidesViewController */
- (void) viewWillAppear:(BOOL)animated {
   [super viewWillAppear:animated];
}

- (void)viewDidAppear:(BOOL)animated{
   [super viewDidAppear:animated];
}


推荐答案

检查出来: https://devforums.apple.com/thread/201431
如果您不想全部阅读 - 某些人(包括我)的解决方案是在主线程上显式调用 presentViewController

dispatch_async(dispatch_get_main_queue(), ^{
    [self presentViewController:myVC animated:YES completion:nil];
});

可能iOS7正在弄乱 didSelectRowAtIndexPath 。

Probably iOS7 is messing up the threads in didSelectRowAtIndexPath.

这篇关于UITableView和presentViewController需要2次点击才能显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆