Login screen shown just once - iphone

i'm making app based on tab bar with two tabs. My problem is that i have to implement authentication view "loginView" on one of tabb's view, and when the credentials are saved i want show another data everytime tab is tapped. what's the best way to do it ?

Store a boolean in your user defaults, something like 'loginShown', then, in your appplicationDidFinishLaunching method, check if the 'loginShown' is set, and if not, present a modal view controller which is your login view.

You can use a modalViewController for Login so you can have some other view beneath it. For saving credentials for Login so that the user does not have to log back in, you can store it in the KeyChain.
Use this reference: http://log.scifihifi.com/post/55837387/simple-iphone-keychain-code

Related

Refresh Tab View in swift

I made an app with an login system. For those users who logged in I want to show a different content. When i switch through the tabs there is still the content shown, which is loaded when I start the app.
How can I change that?
on each controller, you can refresh the display by loading the content in viewDidAppear instead of viewDidLoad

Presenting login and registration view

I am working on an app whereby the user will have the login before using the services. How should I do about doing so, considering the user might register for an account through a UIButton on the login page, which will bring the user to registration view.
Can I use presentModalView to show the login view? If so, how do present I the registration view? Upon successful registration, the user will be auto logged in with the newly created account.
You should create a Modal View Controller (Login View Controller) and set that inside a UINavigationController. If you use a Registration UIButton there, you will be able to navigate to the RegistrationViewController and based on the events happening, you can choose to dismissModalViewController.
A detailed explanation on what you are looking for... is provided here - Show / Hide tab bar !!

Reset the whole view

I have a UITabBarController, each tabs governs it's own UITableViewController. I have a singleton User object in my app and I also have a logout button in which logs out the user and presents a modalViewController of the login page. When I logout I also have the User object to send a postNotification to the three UITableViewController in order to reset the view and stuff. The question is how do I reset the view so it's fresh like when someone starts with the app again, clearing previous data? What's the best way to do this? Thanks
When each tableview controller receives the notification, it can just empty the data array and reload the table.

ViewController data sharing

So I have two view controller that I load on the app delegate when the app loads. One is for a login page where I have a username and password and the other one is a UITabBarViewController. After the user login, I just remove the login view and therefore showing the UITabBarViewController. The problem is that in my UITabBarViewController, I need the username and password from the ViewController. How can I solve this?
ADDITIONAL INFO:
Here's basically what I want to do:
Application starts with an Logon on page: User ID, Password and Logon button
On clicking the logon button, after validating the credentials, we've to take the user to the next screen with
an Navigation Bar on the top (essentially an UINavigationController)
Table view
Tab Bar in the bottom
Now after logging in, I want all the ViewControllers in the UITabBarViewController to be able to get the username and password that the user enters in the first login screen.
I think the best design is to have the your controller for the tab bar present a modal view controller for login. The controller tab bar would then be the delegate of the LoginViewController and the LoginViewController would notify its delegate when the login is complete. When the login is completed successfully then the controller for the tab bar can dismiss the LoginViewController.
Now I wrote this code after you updated the answer. You can figure out how to add the UINavigation bar and table views your self. The question is about passing data between view controller not me answering how to through a bunch of views together. I highly recommend to iTunes U course from Stanford on iOS programming if you want to learn more about putting many views and controllers together for a complete app.
I provide a full, complete and working example demonstrating proper use of delegates to share data between the LoginViewController and a UIViewController (In your case the UIViewController would be replaced by your tab bar controller). I also demonstrate how to use NSUserDefaults to save this data which is accessible from elsewhere is the app.
All the code for the example can be found here.
1 Use root controller to share the data.
You can put the data in your root controller and the root controller creates two view.
The root controller can transfer the data to its child views.
2 Or use class constructor.
When you create the views, you can give them parameters with data.
That is not a big Problem.
You can create two NSString variables in the appDelegate class and set the property to them. So that you can access those variable in the entire project.
You will set the values in the login page and you will access those in the tabBarController.
Thats it.
Reagards,
Satya

How do I get a login screen on an iPhone app (using tabBarController)?

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
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.
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.