简体   繁体   English

从AppDelegate取消viewController

[英]Dismissing viewController from AppDelegate

I am presenting a tutorial view, from the AppDelegate: 我正在从AppDelegate提供一个教程视图:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

....

  EERootVC *rootVC = (EERootVC *)self.window.rootViewController;
    UINavigationController *navcon = (UINavigationController*)rootVC.contentViewController;

    EETutorialRootVC *rootTutorialViewController = [rootVC.storyboard instantiateViewControllerWithIdentifier:@"EETutorialRoot"];

[navcon pushViewController:rootTutorialViewController animated:NO];

return YES
}

How can I dismiss this new view once completed? 完成后,如何取消这个新视图?

I've tried this: 我已经试过了:

[self.navigationController  popViewControllerAnimated:YES];

Which works, but the view it returns to seems to be cut off (shifted up?) 哪个可行,但它返回的视图似乎被切断(向上移动?)

Its not going to be self because calling self in AppDelegate is referencing itself (which will be AppDelegate ) 它不会是self因为在AppDelegate调用self会引用自身(将为AppDelegate

If you want to dismiss it from the AppDelegate you simply do the same thing you did to present it: 如果要从AppDelegate消除它,只需执行与呈现它相同的操作即可:

[rootTutorialViewController popViewControllerAnimated:YES]; 

But your more than likely not going to dismiss it in the AppDelegate , your more then likely going to dismiss it in the view controllers main class, which is where you would call self 但是您更有可能不会在AppDelegate关闭它,然后您更有可能在视图控制器主类中关闭它,这就是您将自己称为self的地方。

Mmm, it seems you work with some custom setup that you have to provide insight in, so we can give you a better answer. 嗯,看来您需要使用一些自定义设置来提供深入的了解,因此我们可以为您提供更好的答案。

If you window.rootViewController would be an instance of UINavigationController you'd have pretty default behaviour and if you'd push and pop ViewControllers, everything would look good. 如果window.rootViewController是UINavigationController的实例,则将具有默认的行为,如果将ViewController推入并弹出,则一切看起来都会很好。

But you are getting the UINavigationController from a custom property of your window.rootViewController. 但是,您是从window.rootViewController的自定义属性获取UINavigationController的。 That suggests that EERootVC is some custom ContainerViewController and my bet is something goes wrong in there where you add the EERootVC.contentViewController to it's view and set it's frame. 这表明EERootVC是一些自定义的ContainerViewController,我敢打赌,在那里您将EERootVC.contentViewController添加到它的视图并设置它的框架是有问题的。

For example, set the UINavigationController as the Window's rootViewController and I bet it works as supposed too. 例如,将UINavigationController设置为Window的rootViewController,我敢打赌它也能按预期工作。

Other then that, you push it without animation, and dismiss it with animation. 除此之外,您可以在不使用动画的情况下将其推送,而在使用动画时将其关闭。 For a good user experience you probably want to think about that approach again. 为了获得良好的用户体验,您可能需要再次考虑该方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM