在presentViewController:animated:completion之后,模态viewcontroller用户界面不响应: [英] Modal viewcontroller UI not responsive after presentViewController:animated:completion:

查看:340
本文介绍了在presentViewController:animated:completion之后,模态viewcontroller用户界面不响应:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序有一个根视图控制器,在应用程序的开头会显示

My app has a root viewcontroller, which at the start of the app displays

  • 登录viewController视图(如果用户未登录)
  • 主viewController视图(如果用户已登录)
  • login viewController view if the user is not logged in
  • main viewController view if the user is logged in

AppDelegate代码:

AppDelegate code:

- (BOOL)              application: (UIApplication*) application
    didFinishLaunchingWithOptions: (NSDictionary*) launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]];

    self.window.rootViewController = [[RootViewController alloc] init];

    [self.window makeKeyAndVisible];

    return YES;
}

以下是RootViewController中使用的代码:

Here's the code used in RootViewController:

@implementation RootViewController

- (void) loadView
{
   [super loadView];

   // here mainViewController and loginNavigationController are initialized
}

...

- (UIView*) view
{   
   [super view]; // this invokes loadView

    return self.isLoggedIn ? self.mainViewController.view : 
                             self.loginNavigationController.view;
}

....

- (void) userDidLogin
{
     [self.loginNavigationController presentViewController: self.mainViewController 
                                                  animated: YES 
                                                completion: nil];
}
@end

如果用户未登录并按下登录按钮,则会显示主viewController.

If the user is not logged in and presses login button the main viewController is presented.

问题在于,在显示了主要的viewController之后,我无法与任何UI元素进行交互.例如,我有一个tableView作为主viewController的子视图,当我尝试滚动它时,在调试面板中收到以下警告:

The problem is that after main viewController is presented, I'm not able to interact with any of the UI elements. For example, I have a tableView as a main viewController's subview and when I try to scroll it I get the following warning in debug panel:

 <UITableView: 0x202a4000; frame = (0 0; 310 548); clipsToBounds = YES;
 gestureRecognizers = <NSArray: 0x1fd9f570>; layer = <CALayer: 0x1fdccff0>;
 contentOffset: {0, 0}>'s window 
 is not equal to <RootViewController: 0x1fd9f7d0>'s view's window!

推荐答案

好,所以在查看更新的代码后,我看到您拥有一个rootViewController并动态地给出了您认为应该呈现的视图.问题是,rootViewController负责根视图,而其他两个视图控制器则管理自己的视图.您不应该传递其他视图控制器的视图.

Ok, so after looking at the updated code I see that you have a rootViewController and are dynamically giving the view you think should be presented. The thing is, the rootViewController is in charge of the root view while your other two view controllers manage their own views. You should not be passing a different view controller's view off.

最后,您似乎想有条件地设置rootviewcontroller.因此,让我们来看一下应用程序委托.我认为您应该让您的应用程序委托执行以下操作.在运行时弄清楚要显示哪个viewcontroller.然后,使该应用程序成为rootviewcontroller.

So in the end it looks like you want to conditionally set your rootviewcontroller. So lets look at the app delegate. I think you should make your app delegate do something like this. Have it figure out at runtime which viewcontroller to present. Then make that the rootviewcontroller for the app.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    UIViewController * resolvedRootViewController = [self someMethodThatCorrectlyGivesRootViewController];

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.rootViewController = resolvedRootViewController;
    [self.window makeKeyAndVisible];

    return YES;
}

这篇关于在presentViewController:animated:completion之后,模态viewcontroller用户界面不响应:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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