开发者

Best way to accomplish this scenario with viewControllers - iPhone

I'm writing an app that will allow iPhone users to login to their accounts. Once logged in the user can pull information, change passwords, change other types of data via webservices. I'm new to iPhone programming and I'm a bit confused on my viewController setup to handle this. What I would like to do is the following; 1) if the user is NOT logged in - display a view which takes up the entire screen displaying my login/password text fields etc. ( I will have some conditionals set in place checking to see if the user has u/p saved in a plist)

2) if user is logged in or once the user logs in, remove the current full size view and load the tabBar view. If the user logs out then the 开发者_JS百科main login view will load.

I will need two viewControllers for this particular scenario? I've read a great deal on view controllers. Read all of the Apple documentation but I still get confused since there are so many options/methods to use.

As always I thank you in advance.

T


Just one of many possible options:

Create LoginViewController and UITabBarViewController. Application delegate will check on start-up whether it already has user's credentials and show the appropriate controller

if ([dataModel hasUserCredentials])
  [window addSubview:[tabControlle view]];
else
  [window addSubview:[loginController view]];

LoginViewController performs log in and notifies app delegate:

- (void) loginComplete
{
  // XXX animation?
  // XXX view(Will/Did)(Appear/Dosappear) and all the stuff,
  [[loginContoller view] removeFromSuperview];
  [window addSubview:[tabController view]];
}


Here is how I would do it:

  • The tab bar controller is your main view controller. You initialize it first (in the main NIB file) and add it to the window in your app delegate.

  • In application:didFinishLaunchingWithOptions:, you check whether the user is already logged in or not. If not, you immediately present your login screen as a modal view controller. If you do this without animation, the user will not notice that the tab bar controller is already present underneath.

  • When the user logs in, you dismiss the modal view controller and your tab bar UI becomes visible.


You should look at creating a Navigation-Based application. This will have a UINavigationController built in. You can use that to control your windows.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜