I cannot figure this one out. Any help much appreciated..
I have a programmatic UITabBarController which has 4 tabs.
When someone selects one of the tabs (all of which are instances of the main viewController), the subsequent viewDidLoad method will trundle off and fetch some XML from the server and parse it.
As there is a slight delay while it does this, what I want to happen is for a UIActivityIndicatorView to appear when someone selects a new tab and then to disappear when the NSXMLParser delegate (in this case, self) responds to parserDidEndDocument.
When I stick a NSLog at the beginning of the viewDidLoad it appears instantly in the Console and when NSLog in parserDidEndDocument, similarly there is no delay. However, when I stick in an UIActivityIndicatorView in there, it won't appear at all.
I have figured that this is because I am using
[self.view addSubview:activityIndicator];
which is adding a view to the new viewController which hasn't loaded yet.
Question:
What is the correct procedure for doing this?
Should I be adding a subview to the main window first?
Should I be adding a subview to the old viewController view? Then removing it when the user steps back?
There is probably an easy answer for all of this but I can't see the wood from the trees. I'm staring at hundreds of lines of code breaking out into a cold sweat.
If anyone could help out, I would be really grateful.
Having done some thing very similar, I would have a "populate" method that gets loaded from the new view controller. So in your viewDidLoad method, you would (in this order)
1-Add the activity indicator, start animating.
2-Start your XML parsing methods.
When your XML is done parsing, then you setup the view, populate your tables, etc.
There are probably 75 billion ways to do this, but that's how I have done this in the past.