Iphone knowing when going back in navigational view control - iphone

I'm using a navigation based view controller on my iPhone app that uses an RSS feed on-load of a nib to bring back results, then another xml call when you select one. Is there an action when you go back on the second view controller to the first, the reason I ask is that it's reloading the first results again (going off to the server) as it's in the viewdidappear. How do I tell it not to re-load the results?
Tom

Move the code to the ViewDidLoad it is only called when the view gets loaded.

Related

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.

Prevent Object Release in Storyboard

I'm looking after a solution to prevent object release in storyboard views.
Here is the deal, I have a storyboard view which contains data grabbed from JSON. This view has relation with another view (First View:List of items -- Second View:Item Details). Now when I tap on an item in first view, it goes to another view and shows the detail (using segue). BUT when I go back to the first view, it needs to grab the data from JSON again. (makes the user angry)
I'm aware of using Tab template, but I can't due to the application user requirements.
I'll be so much appreciated if anybody could help me.
Gratitude.
You are incorrectly implementing the Model-View-Controller pattern. Views should never fetch or hold data. They simply display it. View Controllers also do not hold data. Views and view controllers can be thrown away any time they're not on screen. This is by design.
Create a model class that is responsible for talking to the server and holding the resulting data. The controller should hand the model to the view, and the view should just display what it finds in the model.
I think you need to do a modal Segue from your First View to the Second View. Then when you are finished with the Second View execute [self dismissModalViewControllerAnimated:YES]; in the Second View to dismiss the Second View and return to the First View. This should then display the First View once more with the data.

UINavigationController reloading UITableView

In my application I am parsing XML to create a UITableView. When a user selects a row it changes the file that it is parsing and reloads the UITableView.
I want to create a back button so that the user can go back the the previous XML page they were viewing.
In short how can I tell the navigation controller to create a back arrow for this page when all i am doing is reloading my UITableView?
I'd strongly suggest building another controller (i.e. UITableViewController) and push that instead of just reloading the table. This makes the button automagically, and (major plus here), it animates the whole digging down / stepping back in a way that the user is expecting it.
As a side note, I didn't manage to get a back-style button once I tried it, just a plain normal button (make a new button and set it at the navigation bar).
What you're describing is a navigation. Rather than reloading the table's data, simply push a new view controller onto the navigation stack every time a row is tapped. This is a fundamental pattern in iPhone development. Here is Apple sample code for a multi-level drill down table view.

iphone - how to mentain the state of UIWebView?

i am having a UIWebView showing and HTML page that has some checkboxes, radio buttons. My Application has tabbar controller that switches b/w two controllers. How i can maintain the current state of UIWebView. ( e.g. i have selected a checkbox and i change the tab and go to other ViewController and again come back to UIWebView. the WebView resets itself and goes to the start... i want to maintain the state of UIWebView ( all the checkboxes clicked) .. how i will do that ??
any idea ??
thanks in advance
It sounds like you're loading your web view in viewDidAppear:, or some other method that gets called each time you switch to the tab. If you load your web view in viewDidLoad:, it will only get loaded once, and will retain its state when you switch tabs.
EDIT: When I wrote this answer back in 2009, I apparently didn't understand the view controller life cycle as well as I thought I did. Corey Floyd was right. The viewDidLoad: method can also get called multiple times, because UIViewController will unload its view in low memory situations if the view isn't being displayed. When the user switches back to the view, viewDidLoad gets called again to reconstruct the view.
How embarrassing.
I have an idea that might help:
to get the status from your app to the webpage, give the variables' values as request parameters with the called URL and let the webpage handle them and view the form elements accordingly.
to get the status from the webpage back to your app, let the webpage be refreshed each time any of its element is updated, and with the new URL give the new values of the changed elements. Back to your app, you can implement the UIWebViewDelegate and inside the method WebViewDidFinishLoad (or WebViewDidStartLoad as you prefer) use the webView.request.URL to parse the GET parameters and update your app accordingly.
hope this will help.

Best way to load an application like it was in its previous state when it was terminated

I would like to learn the best practices in reloading the application state, such that when my app is started, it should automatically load the "correct" view/subview when it is opened again.
In my particular case, my app has a bunch of view controllers, each taking care of a UITableView. I would like for my app to "jump" to the correct node within my table view hierarchy when it is opened again.
Building on what Marc said, assuming you've got a base view controller, and then one or more levels of 'drill-down', load all your view controllers up to the 'current' one using [navigationController pushViewController: viewController animated: NO]. Then, when the user hits the Back button, they'll be presented with the pre-loaded previous view controller. A good example of this is the "Contacts" app, which preloads the Groups view controller, then pushes a view controller for the current group (usually "All Contacts") on top of that.
Check Apple's DrillDownSave sample app:
"Demonstrates how to restore the user's
current location in a drill-down list
style user interface and restore that
location when the app is relaunched."
http://developer.apple.com/iphone/library/samplecode/DrillDownSave
You'll need to associate an identifier with each view controller, and save that value to the user defaults when the current view changes. The next time you launch, read that value and you'll know which view controller you need to load initially.
I've published a little library to help doing these kinds of things. I'm already using it in an app I've published on the App Store and it's a lot smoother than implementing NSCoder for every view manually :P