开发者

Another basic question

开发者 https://www.devze.com 2023-03-12 18:13 出处:网络
So I have 2 tabs in tab bar controller. tab 1 is the rootController. tab 2 is a tableviewcontroller which gets user information (like signing up)

So I have 2 tabs in tab bar controller.

tab 1 is the rootController. tab 2 is a tableviewcontroller which gets user information (like signing up)

What happens now:

Tab 1 appears first, and I need to click on tab 2 .

What I need:

When I open the app, I want the app to start off with Tab 2 (if there are no users in the app ). This开发者_JAVA百科 should be the very first screen. And then onwards (if there is an user) it should work with tab 1 as the root controller, and the 1st screen.


Do tabBarController.selectedIndex = 1; or tabBarController.selectedViewController = loginViewController;

In application:didFinishLaunchingWithOptions:,

if ( [users count] > 0 ) {
    self.tabBarController.selectedIndex = 1;
} else {
    self.tabBarController.selectedIndex = 0;
}

This assumes that users holds all your users information. Seva's suggestion for using modal view controller is definitely a better approach to deal with Login's. If by users you mean profiles, then this isn't a bad approach either.


Do you really want the user to be able to switch to the root tab without completing the login? The tab UI suggests that the tabs are more or less functionally independent of one another; for a required login, a modal view controller is a better metaphor.


One way you could check for users is the do something like this:

if(![[NSUserDefaults standardUserDefaults] boolForKey:@"firstTime"])
{
    //login view show
    [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"firstTime"];
}

Or if you are using a database, you could have a query and then do something based on that.

But I agree w/ Seva, you might want to show the view some other way that doesn't let the user jump views before they are done doing the sign in.

0

精彩评论

暂无评论...
验证码 换一张
取 消