2013-04-21 32 views
0

此代碼從我的AppDelegate從我的應用程序,這不是用故事板和normaly這撥碼開關視圖 -如何從appdelegate切換視圖?

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 
{ 
    if (buttonIndex == 0) 
    { 
     LN_ShowNoteVC *showVC = [[LN_ShowNoteVC alloc] init]; 
     _iconBage = _iconBage - 1; 
     showVC.number = _showP; 
     NSLog(@"showVC.number = %i", _showP); 
     _window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
     _window.rootViewController = showVC; 
     [_window makeKeyAndVisible]; 
    } 
} 

現在,我重寫我的應用程序使用故事板.....這個代碼不工作...我得到黑色的窗口

我如何從AppDelegate切換視圖?

+0

你爲什麼要創建一個UIWindow的另一個實例?爲什麼不使用應用程序委託中已有的窗口對象? – lostInTransit 2013-04-21 18:58:50

回答

0

這是答案)),我知道了)=)

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 
{ 
    if (buttonIndex == 0) 
    { 
     LN_ShowNoteVC *showVC = [[LN_ShowNoteVC alloc] init]; 
     _iconBage = _iconBage - 1; 
     showVC.numberPhoto = _showP; 
     NSLog(@"showVC.numberPh = %i", _showP);    
     UIStoryboard *sb = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; 
     UIViewController *vc = [sb instantiateViewControllerWithIdentifier:@"ShowN"]; 
     vc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; 
     _window.rootViewController = vc; 
     [_window makeKeyAndVisible]; 
    } 
}