How to add a logout feature to an iPhone app? - iphone

I've an app with this layout:
When you open the app you see a login screen. You log in and you see a tabbar with 3 tabs. (The loginview is displayed with a presentModalView in the appdelegate of tabbar).
In the third tab there is a logout button. I want when logout button is pressed the app delete NSUserDefaults and shows the loginview again. And if you login again the login screen disappear and you see the first tab of the tabbar.
How can I do this?

Do as follows,
Place your login view in first view controller.
Place your tabbar controller in second view controller.
Store the second viewcontroller instance in appDelegate (this will be used for navigation).
Now when the logout button is pressed,use the stored instance navigate your view.

Related

How to logout of app in Objective-C?

I am doing an app in which on startup of App,a tabbarController with Search and Login views will be presented.When I click on Search tabbaritem SearchView wil appear.When Login tabbaritem is clicked Login view will appear ..When the Login is successful a tabbarcontroller with Four tabbaritems(Search,MyProfile,MyActivities,Logout)will appear.Now when I click on logout I have to logout of the account and I need to show again the startup view.
Any help would be appreciated..
its related with your application architecture. i would like to divide your question :
I m pretty much new to objective-C and I m doing an app in which on startup of App,a tabbarController with Search and Login views will be presented.
Reply: Initially you need to have a navigation controller in the AppDelegate which will work like a parent navigation controller and you need to add your tabbar controller as a rootviewcontroller to it, it will help to get out of the second tabbar controller when you want to logout.
When the Login is successful a tabbarcontroller with Four tabbaritems(Search,MyProfile,MyActivities,Logout)will appear
Reply: Now when you get logged in then you will push a new tabbar controller with 4 tabs, it will get pushed on the parent navigation contrller (that we created in app deleate) .
Now when I click on logout I have to logout of the account and I need to show again the startup view
Reply: Now when you want to logout and after doing all the logout related stuff(like closing the session etc) if you want to pop the view controller like [self.navigationController popViewController] it will not going to help you. as the self.navigation controller is the navigation controller of the new tabbar (of 4 tabs, that you pushed after login ). So you need to access the parent navigation controller here, which we created in app delegate into the Logout view controller, like : [appDelegate.navController poptoRootViewController] .
So the important point here is you need to have access and control over the parent navigation controller.
Hope this helps.

Adding Login View to an App using Tab Bar Controller

I've created a small iphone app that contains a tab bar controller that has been created on the MainWindow.xib. The App Delegate contains the root controller outlet. I'm wondering how I can work in a login screen that will direct the user to my view controller containing the tab bars.
Current Solution:
On didFinishLaunchingWithOptions add subview "RootController" which loads my MainWindow.xib view with tab bars. Then call "presentModalViewController" to present the LoginViewController as a modal. On the login view controller, the login button click calls the AppDelegate to dismiss the modal.
Does anyone know of a better solution? Possibly a solution that doesn't load the page with tabs until after the user has logged into the app.
Thanks!
Make a separate View Controller (lets say A)
in didFinishLaunchingWithOptions check if user is logged in .. if not show A..
implement delegation and pass back login result to the app delegate...and then load the tab bar View

navigating to a TabBar from different ViewControllers

I am trying to build an app that has a landing screen with a link to either "signin" page or "sign up" page. The meat of the app is a tabbar. Where would be the right place to implement the tabbarcontroller given that a user can have the following flow:
landing page - >sign in -> main app
landing page - > sign up -> main app
straight to main app if the user logged in already
Is it possible to do that in the AppDelegate? But then, how do I go back to the appDelegate if I am at the "sign in"/"sign up" page?
Thanks so much for the help!!
Create a modal view that pop ups (the landing page) if the user is not signed in/up. Once they either sign in or sign up, you dismiss the view.
Just create another view and the xib, and if you the first view you load detects they are not logged in (example: say you have a tab bar with Twitter Feed, Facebook Feed, and SO feed, your first view is the twitter view, it senses you aren't signed up/logged in for your awesome service, it calls a modal view to sign in/up) Once users are done with this you dismiss the modal view.
Here's the official documentation: http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/ModalViewControllers/ModalViewControllers.html
UINavigationController *loginview = [[UINavigationController alloc]init];
[self presentModalViewController:loginview animated:YES];
To dismiss it (from within the login view)
[self dismissModalViewControllerAnimated:YES];
For Landing Page / Sign in / Sign Up Page use a seperate view controller (For example) LoginViewController and set it as a ModalViewController in the viewDidLoad of your first tab of your tabbarcontroller.
If login is successful, pop the modalViewController, and you will have the tabBarController.
If you need to know the implementation of this, go to this link -> -> Show / Hide tab bar

iPhone Login -> tabbarcontroller

I have created an app and a login and would like to join them together with no luck. The app has a tabbarcontroller with navigationcontrollers via tableviewcells to drill down to other views of the app.
As I am having no luck in joining the two. I have tried to build on from the login that I have done. I can push to a new view but it does not show a tabbarcontroller etc on the next view. I have seen various forums with people having this problem as well.
So, my question: How can I make a new page (login) open to a TabBarController instead of a view (in the middle of my app, not at the launch)?
Does anyone out there know how to solve this issue?
Use navigation controller in tab bar controller. lets say the navigation controller is its first view controller. Now when the root view controller of the navigation is being displayed, you can see the tab bar. Now if you keep pushing new view controllers in this navigation controller, the tab bar wont hide itself.
However if you present some view controller modally, it would hide itself.
As far as login is concerned, i will check if user has logged in or not. if no, then i would set the root view controller of navigation controller as loginviewconroller else some home page.
I would check the if the user is logged in in the first viewController that get loaded.
From there I would present the loginViewController via the presentModalViewController method.
The use will not see the tabbar if you set the withAnimation:NO.
Now just dismiss the login viewcontroller when the use is logged in.
One could also send a notification that the is logged in, so that viewcontrollers can update them self for the no logged in user.

Iphone UITabbarController

I have a iPad application where i am using more than one Views. The thing is i want to display the TabbarController page while clicking on Button that is on main page. I am able to call the TabBarController directly from delegate method like adding TabBarController to MainWindow in Inspect window. But the thing is i am asking for users to first login to application and after successful loging, Dashboard appears where i have Buttons. Clicking on button i am displaying Tableview in one Tab bar and in another Tabbar Add to list form.
Thanks in advance,
Sam
What I can get from your post is that you want to have the user log in before the Tab Bar appears with your views.
If that's the case, then you want to set your login view as the main view of the window, and then after they log in set the view to be the view of the Tab Bar.