Iphone 从一个导航控制器切换到另一个导航视图控制器
我正在开发一个应用程序,其中使用两个导航控制器和uilocalNotification 第一个导航ViewController N1有两个ViewController v1和v2 第二个导航ViewController N2有两个ViewController v3和v4 另外,当应用程序处于后台时,如果出现UILocalNotification并且我单击它,应用程序应该检测显示的是哪个导航控制器和哪个viewController,然后切换到另一个navigationController的viewController 例如: 如果显示N1中的v2,则 单击通知后, 然后显示N2中切换到v3Iphone 从一个导航控制器切换到另一个导航视图控制器,iphone,uiviewcontroller,uinavigationcontroller,Iphone,Uiviewcontroller,Uinavigationcontroller,我正在开发一个应用程序,其中使用两个导航控制器和uilocalNotification 第一个导航ViewController N1有两个ViewController v1和v2 第二个导航ViewController N2有两个ViewController v3和v4 另外,当应用程序处于后台时,如果出现UILocalNotification并且我单击它,应用程序应该检测显示的是哪个导航控制器和哪个viewController,然后切换到另一个navigationController的view
如何做???只需将下面的方法粘贴到
AppDelegate.m
文件中,并在需要更改UINavigationController
时调用特定的方法即可
例如:如果您处于N1
的v2
中,并且通知已更改,则调用类似于bellow的bellow方法
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate setRootViewControllerN2];
使用以下方法切换带有动画的导航控制器
1。setRootViewControllerN1:这是用于设置带有N1 navigationController的RootViewController
-(void)setRootViewControllerN1{
self.window.rootViewController = N1;
[self.window makeKeyAndVisible];
CATransition *animation = [CATransition animation];
[animation setDelegate:self];
[animation setType:kCATransitionFade];
[animation setDuration:0.5];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:
kCAMediaTimingFunctionEaseInEaseOut]];
[[self.window layer] addAnimation:animation forKey:kAnimationKey];
}
-(void)setRootViewControllerN2{
self.window.rootViewController = N2;
[self.window makeKeyAndVisible];
CATransition *animation = [CATransition animation];
[animation setDelegate:self];
[animation setType:kCATransitionFade];
[animation setDuration:0.5];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:
kCAMediaTimingFunctionEaseInEaseOut]];
[[self.window layer] addAnimation:animation forKey:kAnimationKey];
}
2。setRootViewControllerN2:这是用于使用N2 navigationController设置RootViewController
-(void)setRootViewControllerN1{
self.window.rootViewController = N1;
[self.window makeKeyAndVisible];
CATransition *animation = [CATransition animation];
[animation setDelegate:self];
[animation setType:kCATransitionFade];
[animation setDuration:0.5];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:
kCAMediaTimingFunctionEaseInEaseOut]];
[[self.window layer] addAnimation:animation forKey:kAnimationKey];
}
-(void)setRootViewControllerN2{
self.window.rootViewController = N2;
[self.window makeKeyAndVisible];
CATransition *animation = [CATransition animation];
[animation setDelegate:self];
[animation setType:kCATransitionFade];
[animation setDuration:0.5];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:
kCAMediaTimingFunctionEaseInEaseOut]];
[[self.window layer] addAnimation:animation forKey:kAnimationKey];
}
我希望这对您有所帮助只要将下面的方法粘贴到您的
AppDelegate.m
文件中,并在您想要更改UINavigationController
时调用特定的方法即可
例如:如果您处于N1
的v2
中,并且通知已更改,则调用类似于bellow的bellow方法
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate setRootViewControllerN2];
使用以下方法切换带有动画的导航控制器
1。setRootViewControllerN1:这是用于设置带有N1 navigationController的RootViewController
-(void)setRootViewControllerN1{
self.window.rootViewController = N1;
[self.window makeKeyAndVisible];
CATransition *animation = [CATransition animation];
[animation setDelegate:self];
[animation setType:kCATransitionFade];
[animation setDuration:0.5];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:
kCAMediaTimingFunctionEaseInEaseOut]];
[[self.window layer] addAnimation:animation forKey:kAnimationKey];
}
-(void)setRootViewControllerN2{
self.window.rootViewController = N2;
[self.window makeKeyAndVisible];
CATransition *animation = [CATransition animation];
[animation setDelegate:self];
[animation setType:kCATransitionFade];
[animation setDuration:0.5];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:
kCAMediaTimingFunctionEaseInEaseOut]];
[[self.window layer] addAnimation:animation forKey:kAnimationKey];
}
2。setRootViewControllerN2:这是用于使用N2 navigationController设置RootViewController
-(void)setRootViewControllerN1{
self.window.rootViewController = N1;
[self.window makeKeyAndVisible];
CATransition *animation = [CATransition animation];
[animation setDelegate:self];
[animation setType:kCATransitionFade];
[animation setDuration:0.5];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:
kCAMediaTimingFunctionEaseInEaseOut]];
[[self.window layer] addAnimation:animation forKey:kAnimationKey];
}
-(void)setRootViewControllerN2{
self.window.rootViewController = N2;
[self.window makeKeyAndVisible];
CATransition *animation = [CATransition animation];
[animation setDelegate:self];
[animation setType:kCATransitionFade];
[animation setDuration:0.5];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:
kCAMediaTimingFunctionEaseInEaseOut]];
[[self.window layer] addAnimation:animation forKey:kAnimationKey];
}
我希望这对你有帮助不!实际上,当单击通知时,如何确定当前显示的是哪个viewcontroller和哪个navigationController…??只需在AppDelegate或UserDEfault中创建一个BOOL变量,保存这一个值并将其从true切换为flase即可。。当在那个时候发生通知时,检查是否为true,然后只调用第二个方法并将该变量设置为false,否则调用第一个方法并将该变量设置为true…我很早就想到了standardUserDefaults,但后来我认为会有一些标准方法来实现这一点。无论如何,thanx!!不实际上,当单击通知时,如何确定当前显示的是哪个viewcontroller和哪个navigationController…??只需在AppDelegate或UserDEfault中创建一个BOOL变量,保存这一个值并将其从true切换为flase即可。。当在那个时候发生通知时,检查是否为true,然后只调用第二个方法并将该变量设置为false,否则调用第一个方法并将该变量设置为true…我很早就想到了standardUserDefaults,但后来我认为会有一些标准方法来实现这一点。无论如何,thanx!!