2013-07-18 70 views
0

我有一個應用程序。在我這樣做時,應用程序是第一次啓動我添加LoginViewController其他明智它將添加splitViewController它工作正常,但問題是,我想當loginViewController被添加,當我按登錄屏幕上的singButton然後它應該添加splitViewController窗口代碼確實是這樣,但是當我按下登錄唱歌但隨後應用程序關閉,當我再次打開它,然後它顯示我splitViewController添加視圖在第一次啓動在iPad應用程序的主窗口

這裏是我的代碼

[[NSUserDefaults standardUserDefaults] registerDefaults:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES],@"firstLaunch",nil]]; 

    if ([[NSUserDefaults standardUserDefaults] boolForKey:@"firstLaunch"]) { 


     [[NSNotificationCenter defaultCenter] addObserver:self 
              selector:@selector(actionNotificationData:) 
               name:@"reloadSplit" 
               object:nil]; 

     [self.window addSubview:[loginViewController view]]; 

) 

    else{ 
     [self.window addSubview:[splitViewController view]]; 

    } 


     -(void)actionNotificationData:(NSNotification *)notification { 





     [self.splitViewController removeFromParentViewController]; 


     window = [UIApplication sharedApplication].keyWindow; 
     if (!window) 
     window = [[UIApplication sharedApplication].windows objectAtIndex:0]; 
    [[[window subviews] objectAtIndex:0] addSubview:splitViewController]; 



     [window makeKeyAndVisible]; 


     } 

這裏是signInButtonAction

   [[NSNotificationCenter defaultCenter] postNotificationName:@"reloadSplit" object:self]; 


      [self dismissModalViewControllerAnimated:YES]; 

我的代碼以

self.splitViewController =[[UISplitViewController alloc]init]; 
self.rootViewController=[[RootViewController alloc]init]; 
self.detailViewController=[[[FirstDetailViewController alloc]init] autorelease]; 
self.loginViewController=[[[LoginViewController alloc]init] autorelease]; 


UINavigationController *rootNav=[[UINavigationController alloc]initWithRootViewController:rootViewController]; 
UINavigationController *detailNav=[[UINavigationController alloc]initWithRootViewController:detailViewController]; 



if ([detailNav.navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)]) { 
    UIImage *image = [UIImage imageNamed:@"Nav.png"]; 
    [detailNav.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault]; 







} 




[email protected]"Jamshaid"; 

[email protected]"NO"; 


    [email protected]"Logout"; 



self.splitViewController.viewControllers=[NSArray arrayWithObjects:rootNav,detailNav,nil]; 
self.splitViewController.delegate=self.detailViewController; 

回答

0

首先添加您的LoginViewControllerself.window.rootViewController諸如此類

(在這裏,我還加的UINavigationController太)

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque]; 

    LoginViewController *loginViewController = [[LoginViewController alloc] init]; 
    UINavigationController *loginNVController = [[UINavigationController alloc] initWithRootViewController:loginViewController]; 
    loginNVController.navigationBarHidden = YES; 
    self.window.rootViewController = loginNVController; 

    self.window.backgroundColor = [UIColor whiteColor]; 
    [self.window makeKeyAndVisible]; 

    return YES; 
} 

,然後在LoginViewController.m

後這是的方法210,其電話時,你挖signINButton

-(void)passToSplitViewController:(UIButton *)sender 
{ 
    [self.navigationController pushViewController:self.splitViewController animated:YES]; 
} 

OR

認沽繼結束碼的didFinishLaunchingWithOptions

//Add the below line only if u need to populate login screen before UISplitViewController! 
LoginViewController *loginView = [[LoginViewController alloc] init]; 

      [self.window addSubview:splitViewController.view]; 

//Add the below line only if u need to populate login screen before UISplitViewController! 

[splitViewController presentModalViewController:loginView animated:NO]; 
+0

我給你我的全部代碼plase看到我的更新代碼 – user2240329

+0

@ user2240329 - 檢查我的另一個答案:) – iPatel

相關問題