在 UIAlertView 和 UIActionSheet 的代理方法中給 [UIApplication sharedApplication].keyWindow 設(shè)置 rootViewController 時(shí)宝磨,假如使用下面代碼:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 1) {
TheViewController *vc = [[TheViewController alloc] init];
[UIApplication sharedApplication].keyWindow.rootViewController = vc;
}
}
And
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0) {
TheViewController *vc = [[TheViewController alloc] init];
[UIApplication sharedApplication].keyWindow.rootViewController = vc;
}
}
Then惑芭,在程序執(zhí)行到這里的時(shí)候,你會(huì)發(fā)現(xiàn)酝碳,界面雖然會(huì)跳轉(zhuǎn)到 TheViewController捍歪,但是在一眨眼間又跳轉(zhuǎn)回原來(lái)的界面户辱。
解決辦法:#####
1、要先導(dǎo)入 AppDelegate
#import "AppDelegate.h"
2糙臼、使用下面代碼來(lái)實(shí)現(xiàn)
TheViewController *vc = [[TheViewController alloc] init];
((AppDelegate *)[[UIApplication sharedApplication] delegate]).window.rootViewController = vc;