views:

478

answers:

2

Hi all,

I am developing a web app (using rails) that I will be launching within a week. I've "jumped the gun" and started working on the iPhone app for the site (I'm new to iPhone development). Using the peepcode iPhone screencasts and the expense/budget demo app from clarkware I've been able to get things going (using ObjectiveResource for iPhone-to-Rails communication). So I'm able to get a tabBarController loading a table with test data populated from my staging server online. Great.

My problem lies in that I need login functionality. The budgets demo app has this nailed but it uses a navigationController. I would like to use a tabBarController (which I'm using currently) to handle the basic functionality of the app.

Here's how I see the app login functionality working when completed:

When a user first runs the iPhone app, the iPhone app will present a login screen (username and password). If a correct username and password is entered the session/user info is saved (preferably to the general/settings app section of the iPhone). The user won't be presented with the login screen again unless the session expires, the user edits the username/password in the general/settings section of the iPhone, or the user deletes the application and reinstalls.

The closest thing to what I have in mind for this process is the Gowalla app.

So I suppose my question is: What is the best way to get a login screen to appear when using a tabBarController? Once I can do this and get authentication taken care of the rest should fall into place.

Please let me know if there's anything I need to clarify - THANK YOU!

-Tony

A: 

Do you want to have the tab bar to display at the bottom? Then just put the Login View Controller as the selected tab by setting the selectedViewController or selectedIndex properties of UITabBarController.

Do you want to have the tab bar display at the bottom but not be actionable until they've logged in? Then set a UITabBarDelegate and override the tabBarController:shouldSelectViewController: method to disallow until login has happened.

Do you not want the tab bar to display until login has been entered (personally I would think this is most desireable)? Then either don't show the TabBarController until you're ready, show the Login View Controller instead... or, alternatively, show the Login Controller as a Modal View Controller over the TabBarController and don't allow it to be dismissed until login was successful.

bpapa
I think I just did your last suggestion before reading your answer!I don't want to show the tabBarController until they login. What I did was I added a navigationController ABOVE the tabBarController and linked it to the appDelegate in the nib file. By doing this the sample login code in budgets demo app shows up before the tabBarController - once the credentials are correct and submitted the login screen (navigationController) vanishes and displays the tabBarController.Is this the right way to do this?
slythic
I'm not sure what you mean but saying you added a navigationController above the tab bar controller. Do you mean in terms of them both being subviews of the window?
bpapa
Hopefully this makes it clearer. This is a screenshot of my MainWindow.xib: http://img.skitch.com/20100303-jsauc62uwauswpsjcb634an937.jpg
slythic
Personally I would say don't have the Tab Bar or Navigation Controller lingering around in memory until you need it. A Tab Bar and a Navigation Controller are supposed to be able to work in unison, so you really shouldn't be overly concerned with which shows up first. Instead, when the user logs in for the first time, show a LoginViewController only. When they login, then create the NavController/TabBarController as you would when they run the app after already having provided credentials.
bpapa
A: 

Hello there!

I am new to iPhone programming, but have done C++ coding moons ago. So far I have created everything programmatically rather than use the nib approach.

For what you what to achieve, I would create a main view controller from the app delegate. Then from this main view controller I would create the login view (UIView) that initially displays and seeks the users login credentials. Once validated, your main view contoller can the create and display (or just display if you created it initially) a tab bar controller with the appropriate view controllers for each tab.

So appDelegate -> Main View Controller -> Logon View

                               -> Tab View Controller + View Controllers

Hope this helps?!

Matthew.

Many thanks Matthew. Now all I have to figure out is how to do it in my free time. ;-)
slythic