Search code examples
iphoneuiviewback-buttonpushviewcontroller

destroy a view when back button is pressed


My navigation controller is organized this way:

FirstViewController -> SecondViewController -> ThirdViewController

in the First I do a search on the web and I display the result in a UITableView when I select a cell I push to the Second where I do another search based on key previously pressed and I display some information and a button for "more info" when I press the button I push to the Third view and this works fine...

The problem is when I press two times the back button for doing another search: when I arrive at the third view I display every time the informations about the first search!

this is because I do the display of information in loadView and this is called only the first time, right?

How should I do?

thank you!


Solution

  • Indeed viewDidShow is called after the view has been loaded and created from the NIB file. This means you should only use that method to do initialization stuff.

    Add a new method and call it everytime you have new results:

    - (void) updateAndShowResults
    {
        // Code to update third view goes here
        // and is always called whenever some new results are available
    }
    

    You'd call it from the first or second view controller like this:

    [thirdView updateAndShowResults];
    

    Hope that helps. Please mark the best answer by clicking the "√" on the left! Thanks.