An easy way to override which screen displays the first iOS

I'm trying a storyboard now , and I have a UITableViewController as my rootViewController . Now in some cases, if my user is not logged in, I want another UIViewController to appear first. I understand that I can execute segue , but, in my opinion, TableView will still try to load, which is not what I want if they do not provide information about this UIViewController m in order to try to appear first (if, for example, the key does not exist in NSUserDefaults ).

So my question is: is there a simple solution that I can add to my appDelegate to " override " the rootViewController from the storyboard, or appear in front of it, and then just click on the abandon this rootViewController in the storyboard?

Thanks!

0
source share
3 answers

You can:

  • Use a different initial view controller (you can specify this in the storyboard). In this view controller, verify that the user is logged on. If so, simply go directly to the table view controller using manual start. If not, display the login screen.

  • Subclass of UITableViewController. Check the input to viewDidLoad. If not, specify a modal login controller.

You probably don’t want to do this in the app’s deletion, as you will need to manually download the storyboard, which means unnecessary code.

0
source

Really similar to this question: Loading UIStoryboard from application delegate

You must set the storyboard identifier in the "Identification" section of the view controller in the interface builder. Then you can get this screen through

 UIViewController *viewControllerToShow = [storyboard instantiateViewControllerWithIdentifier:@"MyViewController"]; 

You end up with something like this:

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:[NSBundle mainBundle]]; UIViewController *vc = nil; if (someKindOfCheck) { vc = [storyboard instantiateViewControllerWithIdentifier:@"MyViewController"]; } else { vc =[storyboard instantiateInitialViewController]; } // Set root view controller and make windows visible self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; self.window.rootViewController = vc; [self.window makeKeyAndVisible]; return YES; } 
+1
source

A simple way would be to set your table partitions to 0 if the user is not registered, for example:

 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { NSInteger numberOfSections = 0; if (userLoggedIn) { numberOfSections = 1; } return numberOfSections; } 
0
source

Source: https://habr.com/ru/post/1206273/


All Articles