0

我有一个应用程序。我正在这样做,当应用程序首次启动时,我正在添加 LoginViewController 否则它将添加 splitViewController 它工作正常,但问题是我希望在添加 loginViewController 并且当我在 loginscreen 上按下 singButton 时,它应该将 splitViewController 添加到窗口代码确实是这样,但是当我按下登录 singin 但应用程序关闭时,当我再次打开它时,它显示我 splitViewController

这是我的代码

   [[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];







}




user_Name=@"Jamshaid";

isClickedLogin=@"NO";


    userLogin=@"Logout";



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

1 回答 1

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

这是 的方法signINButton,当你点击它时调用signINButton

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

或者

将以下代码放在末尾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];
于 2013-07-18T07:13:11.123 回答