简体   繁体   English

强制App导航到AppDidBecomeActive中的特定视图

[英]Forcing App to Navigate to a specific view within AppDidBecomeActive

I want to let the user be able to navigate to a specific view under certain circumstances, when the App runs again from the background. 我想让用户能够在某些情况下(当应用再次从后台运行时)导航到特定视图。

For now I'm using this piece of code to force my App: 现在,我正在使用这段代码来强制我的应用程序:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
                        self.window.rootViewController = self.viewController;
                        [self.window makeKeyAndVisible];

                    return YES;
            }

- (void)applicationDidBecomeActive:(UIApplication *)application {
        if(this situation occurs){
                NavigationViewController *vc = [[NavigationViewController alloc] init];
                            self.window.rootViewController = vc;
                            [vc release];
        }
        eles{
                Password *vc = [[Password alloc] init];
                            self.window.rootViewController = vc;
                            [vc release];
        }
}
- (void)dealloc {
                    //[password release];
                    [_window release];
                    [_viewController release];
                    [super dealloc];
}

@end

However I think my previous view is still running somehow (a timer still runs). 但是我认为我以前的视图仍然以某种方式运行(计时器仍在运行)。 How am I able to release the previous view ans start 'clean' again. 我如何释放以前的视图并再次开始“清理”。

EDIT: 编辑:

The solution was to check if the window has a subview. 解决的办法是检查窗口是否有子视图。 If it has it will be removed from the superview. 如果有,它将从超级视图中删除。 Afterwords the new view is created and added to the view as a subview 后记创建新视图并将其作为子视图添加到该视图

for (UIView *subView in [self.window subviews]) {
                [subView removeFromSuperview];
            }


            self.viewController = [[[MyNewNibFile alloc] initWithNibName:@"MyNewNibFile" bundle:nil] autorelease];
            [self.window addSubview:self.viewController.view];

制作NavigationViewController和password的全局实例,即在appdelegate.h中声明它们,并在创建新的Navigation Controller和password实例之前,始终检查它们是否已创建。如果已创建,则先释放它们,然后创建一个新实例。

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

相关问题 使用URL方案导航到特定视图 - Navigate to specific view with URL Scheme 如何使appDidBecomeActive显示rootViewController的视图? - How do I make appDidBecomeActive show the view of rootViewController? 单击带有Reveal的推送通知时,导航到特定视图 - Navigate to a Specific view on click on a push notification with Reveal iOS Swift-以编程方式导航到特定视图 - iOS Swift - Programmatically navigate to a specific view 以单个视图启动应用程序,然后导航到选项卡视图? - start app with a single view then navigate to a tab view? 从App Delegate执行,导航到子视图 - Performe, navigate, to child view from App Delegate 启动应用程序并导航到先前显示的视图 - Start app and navigate to the view previously displayed 以编程方式导航到iOS主要设置应用,而不是应用特定设置页面 - Programmatically navigate to iOS main settings app, not the app specific settings page 从AppDelegate,Swift导航到TabBarController内部的特定View Controller - Navigate to a specific View Controller inside a TabBarController from AppDelegate, Swift 如何从App委托导航Inner View Controller - How to navigate Inner view controller from App delegate
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM