How can I update a view in the iPhone every time just before the view is displayed? - iphone

I have an application which has 7 tabs with associated views and view controllers. I need a way to update each view when it is selected. I have searched and searched, but cannot find a way to do this.
viewDidLoad will not work, as that only is fired the FIRST time a view is selected.
Capturing the selected tab in didSelectViewController won't work, because since there are more than 5 tabs, one of them is more and it is only fired for the tab itself, not underlying views when selected.
So I guess what I need to know is this: Is there a method I can call for on a view controller that will fire EVERY time just before that view is shown?

You need to implement delegate's -viewWillAppear:(BOOL)animated method for that.

Related

iPhone Storyboard, programmatically calling segues, navigation issues

So I have an iPhone app. It has a simple structure, all based on a UINavigationController.
I have a storyboard that has one view, a segue to another view, etc. Now this other view has a UITextView that I do not want to edit on this screen - if the user taps this, I want it instead to fly over to a second screen which basically has the same text view, but this one is full-screen, and the user will edit the text on that screen before returning to the previous screen.
So I capture the textViewShouldBeginEditing method. I previously, in the storyboard editor, manually created a push segue from the previous view controller to this new view controller, and named it so that I can call it by it's identity, which I do with:
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView
{
// This is called when the user clicks into the textView as if to edit it.
// Instead of editing it, go to this other view here:
[self performSegueWithIdentifier:#"editMemoSegue" sender:self];
// Return NO, as I don't actually want to edit the text on this screen:
return NO;
}
Seems reasonable. And it works. Sorta. It does in fact shoot me over to that other view. That other view's events fire up, I set it's text view to become first responder, I edit the text on that screen. Everyone's happy.
Until I want to use the back button to return to the previous view.
Then I quickly find out - my navigation stack is foobared. Most of the time, I have, for some reason, TWO instances of my new editing controller on the stack, so the first time I hit the back button I get the same stuff over again. Then, oddly, occasionally, it will work as intended, and I will see my previous controller with only one back click.
I started reading the log, and I found this:
2012-12-09 09:41:03.463 APP[8368:c07] nested push animation can result in corrupted navigation bar
2012-12-09 09:41:03.818 APP[8368:c07] Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get corrupted.
2012-12-09 09:41:03.819 APP[8368:c07] Unbalanced calls to begin/end appearance transitions for <SecondController: 0x83881d0>.
So obviously, I'm doing something incorrectly here. The question is, what? And how do I do what I want in the way that correctly appeases the tiki gods of the iPhone framework?
Check to see if the textViewShouldBeginEditing is being called twice. I've noticed that these kinds of delegate calls sometimes are.
How is your #"editMemoSegue" being created on the storyboard? is it created from the textView? if it is then you should recreate it directly from the view controller or from the top status bar on the view controller that way it wont be called twice when you touch the trigger object and when you call it programmatically.

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.

UITabViewController, viewWillAppear does not invoked?

New to iOS, kindly bare if the question is very basic? When I press the tab button multiple times, it is not invoking viewWillAppear function? If I am wrong, then which function gets invoked, each time a tab button is pressed being on the same tabview?
You are correct, viewWillAppear is a little special, it is usually called automatically but in some cases including when you are adding a view controllers view manually (view addSubview:), and also when adding this as a view controller to a UITabViewController it doesn't get messaged.
This however is only for the root view, as you navigate (maybe with a navigation controller) back and forth, that root view's viewWillAppear will get triggered as some point.
In short, if you need to implement something in viewWillAppear in these cases, you should message it yourself when you know it's going to be presented. You can handle this case in your view controller, check out the following article about the matter:
http://www.touchthatfruit.com/viewwillappear-and-viewdidappear-not-being-ca
Good luck.

how to refresh UX data on a ViewController when its TabBarItem gets tapped?

In the view controller that has a UITabBarItem, i realized that viewDidLoad() method only gets called the first time when the tab bar item is clicked. So I dont know how to bring up the dynamic graphics when it's clicked the 2nd time. Can some guru help me on this? thanks in advance.
Should I conform to some kind of delegates or should i do it within didSelectViewController method on the root controller of all the tab bars? If i do the later one, it just seems to be weird since i think the controller that has the corresponding tab bar item should render itself instead of doing the rendering on root controller..
You want to put any code that should run every time the view controller appears in viewWillAppear: instead of viewDidLoad. viewDidLoad is designed for code that should run when the view backed by your UIViewController is created (and then possibly re-created after being thrown away during low-memory situations).
Actually i resolved this by using the parameter passed into the callback didSelectViewController(param).

Calling multiple methods in viewWillAppear with a TabBarApplication

I'm currently working on an application that uses a view controller and a tabBar controller. When a tab is selected I'm using webservices to update this particular view. Each tab calls different services to display different types of data.
I use the viewWillAppear method to call methods when the different tabs are selected but what I would like to do is be able to setup some conditionals to only call the method for the current view/tab was selected.
One of my tabs has two views. Based on the view loaded I would like to call the methods in viewWillAppear that relate to the specific view.
How does one find out which tab-view is currently selected and which view has displayed?
Thanks
You can know which tab and View is being selected by Tag id given to each TabBar Item and View in your nib.
There are few questions on SO which can help you indirectly on this problem. One of them is
How to remember last selected tab in UITabBarController?