按下后退按钮时销毁视图

发布于 2024-10-05 12:49:41 字数 364 浏览 0 评论 0原文

我的导航控制器是这样组织的:

FirstViewController -> SecondViewController ->; 第一个中的ThirdViewController

我在网络上进行搜索并将结果显示在 UITableView 中 当我选择一个单元格时,我会推到第二个单元格,在其中根据之前按下的键进行另一次搜索,并显示一些信息和“更多信息”按钮 当我按下按钮时,我推到第三个视图,这工作正常...

问题是当我按两次后退按钮进行另一次搜索时:当我到达第三个视图时,我每次都会显示有关第一个视图的信息搜索!

这是因为我在loadView中显示信息,并且这只是第一次调用,对吧?

我该怎么办?

谢谢你!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

弃爱 2024-10-12 12:49:41

实际上,viewDidShow 是在从 NIB 文件加载并创建视图之后调用的。。这意味着您应该只使用该方法来执行初始化操作。

添加一个新方法并在每次获得新结果时调用它:

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

您可以从第一个或第二个视图控制器调用它,如下所示:

[thirdView updateAndShowResults];

希望有帮助。请点击左侧“√”标记为最佳答案!谢谢。

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.

绅士风度i 2024-10-12 12:49:41

你可以在viewdidunload中清理ThirdViewController。

You can clean up the the ThirdViewController in viewdidunload.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文