简体   繁体   English

按下后退按钮时破坏视图

[英]destroy a view when back button is pressed

My navigation controller is organized this way: 我的导航控制器是这样组织的:

FirstViewController -> SecondViewController -> ThirdViewController 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... 在第一个中,我在网上进行搜索,当我选择一个单元格时,我将结果显示在UITableView中。在第二个中,我基于先前按下的键进行另一个搜索,并显示一些信息和一个用于“更多信息”的按钮“当我按下按钮时,我会推到第三视图,这很好用...

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? 这是因为我在loadView中显示信息,而这仅是第一次调用,对吗?

How should I do? 我应该怎么做?

thank you! 谢谢!

您可以在viewdidunload中清理ThirdViewController。

Indeed viewDidShow is called after the view has been loaded and created from the NIB file . 实际上,在从NIB文件加载并创建视图之后,将调用viewDidShow 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. 谢谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM