[英]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.
我如何释放以前的视图并再次开始“清理”。
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.