Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it ok to re-assign the rootviewcontroller of the window again and again in this case...?

I have a splitviewcontroller based application, but the problem is the split view comes into picture after two modal views.

  1. for login
  2. some other useful info for the user.

Now I know that splitview controller should always be the root view controller. So what i do is create three objects in my appDelegate class. A , B, and split view controller C.

the order of navigation is A-->B-->C;

so in the app delegate this is what i do..

self.loginViewController=[[LoginViewController alloc] init];
self.window.rootViewController = self.loginViewController;

and then once the login button is pressed this is what I do from the loginView controller..

TSAppDelegate *appDelegate=(TSAppDelegate *)[[UIApplication sharedApplication] delegate];
                appDelegate.meetingsViewController=[[MeetingsViewController alloc] init];
                [UIView
                 transitionWithView:appDelegate.window 
                 duration:0.8
                 options:UIViewAnimationOptionTransitionCrossDissolve
                 animations:^(void) {
                     BOOL oldState = [UIView areAnimationsEnabled];
                     [UIView setAnimationsEnabled:NO];
                     appDelegate.window.rootViewController=appDelegate.meetingsViewController;    
                     [UIView setAnimationsEnabled:oldState];
                 } 
                 completion:nil];

this here presents the second view... and similarly I show the split view controller if some action is performed on the second view controller...

So my question is if it is the correct way to do it... ? (This works fine by the way and also its an enterprise application)

P.S. I also tried making the split view controller as the rootviewcontroller and adding the other view controllers views as its subview but that doesn't work properly.

like image 777
Ankit Srivastava Avatar asked Jan 19 '26 01:01

Ankit Srivastava


1 Answers

Sure, it's perfectly fine to reassign the window's rootViewController.

like image 82
Ole Begemann Avatar answered Jan 20 '26 18:01

Ole Begemann



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!