如何在ipad应用程序中加载SplitViewController的第一个视图

时间:2013-07-19 05:12:47

标签: ios ipad uisplitviewcontroller

我有ipad与splitViewController与多个detailViewController它工作正常但我希望当用户点击登录按钮并转到LoginScreen然后登录按钮时点击登录屏幕然后它应该重新加载整个splitViewController并显示第一个屏幕而不是然后在这里显示我们点击登录按钮的屏幕是我的代码

     - (void) loginPressed
    {
 LoginViewController *targetController = [[LoginViewController alloc] initWithNibName:@"LoginViewController" bundle:nil];
targetController.modalPresentationStyle = UIModalPresentationFullScreen;

    [self.splitViewController presentViewController:targetController animated:YES completion:nil];
}

}        

这是Login ViewController代码中的登录按钮

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

    FirstDetailViewController*targetController=[[FirstDetailViewController alloc]init];

    [self.splitViewController pushViewController:targetController animated:YES] ;

app delegate中的通知代码。

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



    jani=@"No";


   self.window.rootViewController=splitViewController;
   }

这是我的RootViewController,当我们在任何单元格上移动到新视图时,tableView是splitView Conroller中的代码

[self.appDelegate.splitViewController viewWillDisappear:YES];
NSMutableArray *viewControllerArray=[[NSMutableArray alloc] initWithArray:[[self.appDelegate.splitViewController.viewControllers objectAtIndex:1] viewControllers]];
[viewControllerArray removeLastObject];


if (row == 0) {


    self.firstDetailViewController=[[[FirstDetailViewController alloc] init]autorelease];
    [viewControllerArray addObject:self.firstDetailViewController];
    self.appDelegate.splitViewController.delegate = self.firstDetailViewController;







  }

if (row == 1) {



    self.secondDetailViewController=[[[SecondDetailViewController alloc]init]autorelease];
    [viewControllerArray addObject:self.secondDetailViewController];
    self.appDelegate.splitViewController.delegate = self.secondDetailViewController;
}

if (row == 2) {
    self.myLearningViewController=[[[MyLearningViewController alloc]init]autorelease];
    [viewControllerArray addObject:self.myLearningViewController];
    self.appDelegate.splitViewController.delegate = self.myLearningViewController;
}


if (row == 3) {
    self.communityViewController=[[[CommunityViewController alloc]init]autorelease];
    [viewControllerArray addObject:self.communityViewController];
    self.appDelegate.splitViewController.delegate = self.communityViewController;
}


if (row == 4) {
    self.reportsViewController=[[[ReportsViewController alloc]init]autorelease];
    [viewControllerArray addObject:self.reportsViewController];
    self.appDelegate.splitViewController.delegate = self.reportsViewController;
}




if (row == 5) {


    self.walkInViewController=[[[WalkInViewController alloc]init]autorelease];

    [viewControllerArray addObject:self.walkInViewController];

    //self.appDelegate.splitViewController.delegate = self.secondDetailViewController;

    self.appDelegate.splitViewController.delegate = self.walkInViewController;


}

if (row == 6) {


    self.postDataViewController=[[[PostDataViewController alloc]init]autorelease];

    [viewControllerArray addObject:self.postDataViewController];


    self.appDelegate.splitViewController.delegate = self.postDataViewController;


}



[[self.appDelegate.splitViewController.viewControllers objectAtIndex:1] setViewControllers:viewControllerArray animated:NO];    


[self.appDelegate.splitViewController viewWillAppear:YES];
[viewControllerArray release];


}

1 个答案:

答案 0 :(得分:0)

如果没有关于如何在多个细节视图控制器之间移动的更多信息,有点难以回答这个问题。我假设您通过将详细控制器嵌入导航控制器并进行推送和弹出来实现这一目的。

如果这是设置,那么你不应该分配初始化FirstDetailViewController然后推送它。如果FirstDetailViewController首先在屏幕上,那么你推到第二个,最后从那里呈现LoginViewController,你应该做这样的事情:

- (IBAction)signInButtonClicked{
    [[NSNotificationCenter defaultCenter] postNotificationName:@"reloadRoot" object:self];

    UINavigationController *nav = [(UISplitViewController *)self.presentingViewController viewControllers][1]
    [nav popToRootViewControllerAnimated:NO];
    [self dismissViewControllerAnimated:YES completion:nil];
}