Reset the whole view - iphone

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.

Related

IOS: 'Register/Login' view controller and going back to it as necessary

I'm having issues with a Registration/Login View Controller when the user manually wants to Logout of the app.
So, the very first VC of the app is as follows:
REGISTRATION/LOGIN VC : Checks if credentials already exist in the device, if so, automatically attempts to login and pushes to the HOME VC if successful. If there are no credentials then it displays a Registration form in the same VC.
Now, because I don't want people to be able to go back to the Registration/Login VC on their own once they are at the HOME VC, I remove all previous VC's from the navigation array upon loading the HOME VC. (Could this be part of the problem?)
Now, once logged in, users can pretty much at any time deregister and it should bring them to the Registration/Login VC. I do this by performing a segue from the VC with the logout button.
The problem is that when this segue goes through, I get a black screen with only the Navigation Bar on top. While debugging, I can see that the Registration/Login VC's logic does get executed (it checks that the user has credentials, doesn't find them and theoretically makes the registration form visible), but it is all still just black.
I'm not sure what is causing this but it has made me wonder really what is the best approach to having a Register/login VC as root but at the same time making it not be accessible through back-navigation.
Thank you for any help!

Login screen shown just once

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

Reload View only when application is opened Again

My application has tab bar with one of the tabs having a segmented control on navigation bar.
Based on segment clicked different view is displayed using a url.
I am calling the url in viewdidload method.I do not want to use viewwillAppear to call the url as it will be called each time the view is displayed.
I only want to call the url again whenever user closes the application and comes back.
Whats the best way to do this.Should I remove the view controller from and reload it again once the application is opened.
Please use a more descriptive title for your question next time!
There are notifications for this that you can observe in your application:
UIApplicationDidBecomeActiveNotification and UIApplicationWillEnterForegroundNotification come to mind.

Present login screen on app startup

In my previous question on UIView animations I mentioned that I have to simulate the modal behavior for some view. Here I'll explain why and ask about some better solution.
The first view a user should see in my app is the login screen. Upon successful authentication the program checks if the user is a parent or a child (in a family). For each of these roles the app must provide different functionality.
So I designed the app like this:
Declare outlets for the login view controller and a tab bar controller (for the main part of the interface) in my AppDelegate.
In the application:didFinishLaunchingWithOptions: method
Set the rootViewController of the main window to the login view controller.
Make AppDelegate the delegate for the login controller, so it can send notification when it's done its job.
When AppDelegate receives the message on successful login, it determines whether the user is a parent or a child, instantiates the set of view controllers that provide corresponding functionality and passes them to the tab bar controller.
At last AppDelegate switches the rootViewController of the main window to the tab bar controller.
Certainly the user can logout, then the rootViewController is switched back again to the login controller.
I would like to present and dismiss the login screen as if it is a modal view, but AppDelegate only has a bare window, thus I don't have an object to send presentModalViewController: to. This brings up a question:
First of all, is it a good design?
And if it is, how do I simulate a modal behavior correctly?
I think you're on the right track.
However, I always try to get out of the app delegate as soon as I can, leaving it only to do application-level things (like respond to notifications, go in and out of background). In this case, doing so will help you.
In the appDelegate, create a new UIViewController class, something like "startUpController".
Add it's view to the app window.
Then in your startUpController, do everything that you used to do in the app delegate (login, tab bar setup, etc.).
And now, since you're in a view controller, you can presentModalViewController to your hearts content.
Hii,
you should refer this
http://code.google.com/p/tweetero/
https://github.com/jbrien/WordPress-iPhone
Hope this helps!

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