Refresh a view on TabBarController - iphone

I have a TabBarController, with three views, one of which is the settings view. When I go to the settings page, then come out of the app and go back in, I need the view to refresh. Is that possible?

It depends on what you want to refresh, and what your setting looks like?
If your setting view has a done or save button, you can put the refresh code there, [someController.theTable reloadData] for example.
Another way is to put the refresh code inside viewWillAppear: in the view that you want to refresh, info can be found here:
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/cl/UIViewController

Related

Logout issue in TabBar based app

This is quite a common question, but after trying a lot to fix the issue, finally I have decided to post it on StackOverFlow.com
I have a tab bar based app. The tab bar is loaded in AppDelegate.m as follows:
self.tabBarController.viewControllers = #[viewController1, viewController2 , viewController3 , viewController4 , viewController5];
My 5th tab has a button for logout. When user clicks logout, I want to clear/reset entire app and go to login page which is a modalviewcontroller.
I have tried following while logging out:
NSMutableArray * vcs = [NSMutableArray
arrayWithArray:[self.tabBarController viewControllers]];
[vcs removeAllObjects ];//ObjectAtIndex:4];
[self.tabBarController setViewControllers:vcs];
This removes all views from tab-bar. But when I login again, nothing is displayed. I want to show my home screen, i.e. tab item 1 selected by default.
I have read that its not a good practice to call didFinishLaunchingWithOptions again manually.
Is there a way where I can reset all tab-bars and reinitialise them again ?
This will help me solving one more problem that is linked with this situation. When user logs out and log in again, and view controllers are not cleared, then logout page is shown again after login. And not the home view controller.
Please help.
Thanks in advance.
If you really want to start over, you should put a method, lets call it -(void)setupTabBarController, in the app delegate, and at start up you would call it from application:didFinishLaunchingWithOptions:. Later when you want to reset, call that method again from the login page. This method would have the creation of all the tab bar controller's view controllers in it, as well as setting the tab bar controller as the root view controller of the window.
However, it's not really clear that you need to do this, depending on what state all those controllers are in at logout time. Your problem with the logout page being shown again could probably be fixed in a simpler way.
Well, nothing is showing because you removed the views and never added them back in.
There is no need to remove the view controllers from the tab bar after you log out. You can just write a method to reset all the data in each view controller and then set the selected tab to what you desire.
I know, this is not really an answer to your question, but this could maybe help you too (and as I can't comment on post yet i have to post it like this :)).
I had some problems with "resetting" the navigation stack when the user logs out in my tabbar app too. In the beginning I had my tabbar-controller as the root controller and was displaying the login-screen modally but than it was quiet hard reset the navigation stack once the user loged out.
What I ended up doing and it works for me quiet well is, I set the login controller as root controller and after log in displayed the tab navigation modally. On log out I simply dismiss the tabbar-controller again - everything starts from the beginning again.
Maybe you could try this and see if it is easier to handle.
You should be add tabBar controller on second view controller. main view controller show home screen. when you navigate second view controller then you add tabBar here.

Xcode - Manually load a view controller

What I am asking may be impossible and sound weird, but here it goes.
Here is similar to what I want to achieve:
A user opens the app for the first time, there are two tab bars, in the first one (he has not tapped the second one yet) he presses a button that should initiate a progress view and text view changes and other view changes EVEN THOUGH the user has not loaded the other view controller by clicking the second tab bar.
So, is there a way to generally load a view controller before the user manually loads it himself, I know calling viewDidLoad manually will not help, any suggestions? Pretty confusing, it is like modifying a view but the controller has not loaded yet...
Thanks!
Make the changes in the other view controller and then let the controller configure its own view when it does its natural loading.

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.

how to restore view to view did load

i am using a view that displays multiple items depending on user input and i would like to when i press a button to be able to go back to the first view generated in the view (viewDidLoad).
I tried numerius methods such as adding an action to a selector to load a -(void) that reloads the view however that crashes too.
I havent been able to find a resolution to this problem for quite some time
Thanks
You may need to post some code to get a better answer. I'll assume that you are showing views on your original view, and some of them cover your original view. If this is the case, the original view still exists, and you simply need to remove the views that were added later. If they were presented as a modal dialog, remove with [childViewController dismissModalViewControllerAnimated:YES]. If you added them with [self.view addSubview:childView], remove them with [childView removeFromSuperView]. If you are using a navigation controller, you'll similarly need to pop your child view. Instead of adding and removing views you could hide or show them if they should only be initialized once. If you want a more specific answer, reduce your code to the minimum required to make it happen and post it!

Return to a removed view controller

Here is the situation, I have a login page as the initial rootView of a tab bar. Once the login process is done, the view is removed from the navigation controller, so you don't navigate back to it. I have places in the app where you can logout. The logout process works fine, but when I try to forward the user back to the initial login view (the one we removed) from inside the same tab bar item, I can't seem to reset the view controller stack to contain only the desired element. Is this a question of where I am changing the view? It just doesn't seem to remove the current view. I have tried alot of stuff, popto, popview, and many others, and nothing seems to work properly. Has anyone had to deal with this?
Take a look at the View Controller Programming Guide and the various way to alter the navigation stack (push, pop, set, etc).
Look into making your login view controller into a modal view controller, which pops up when credentials need to be entered.
A modal view controller is perfect for view controllers that you don't need to keep around, but which can be needed at different points in your application usage "flow".
Laurent's link will explain to you what the different options are for a navigation stack, and Apple's document suggests contexts in which those different view controller types are useful. I highly recommend reading it.