[英]reload view did load on returning to view from other tab (iPhone interface builder)
I have 2 views controlled by a tab bar controller. 我有2个由标签栏控制器控制的视图。
The issue that I am having is that on returning to my 1st tab from my 2nd, I ideally need all of the 1st view's data to have reloaded based on the changes I made in the 2nd tab. 我遇到的问题是,从我的第二个选项卡返回到我的第一个选项卡时,理想情况下,我需要根据我在第二个选项卡中所做的更改重新加载所有第一个视图的数据。
It is possibly better not to explain why, as my fumbled attempts at over-complicated code with numerous work-arounds will likely alarm you. 最好不要解释为什么,因为我对带有许多变通办法的过于复杂的代码的摸索尝试可能会警告您。
So basically, can i get viewDidLoad to redo itself when i go back to the view from another tab? 所以基本上,当我从另一个选项卡返回视图时,是否可以让viewDidLoad重做自身?
EDIT: and the answer is: viewWillAppear instead of viewDidLoad i think (can't answer own question for 8 hours) 编辑:答案是:我认为viewWillAppear而不是viewDidLoad(8小时无法回答自己的问题)
Rather than reload every time on viewDidAppear, in most cases you're better off sending a message to view 1 telling it to reload next time it appears. 在大多数情况下,最好不要在viewDidAppear上每次重新加载,最好发送一条消息通知view 1,告诉它下次出现时重新加载。 This avoids unnecessary reloads (which can be bad for user experience and use unnecessary bandwidth). 这样可以避免不必要的重新加载(这可能不利于用户体验并使用不必要的带宽)。 There are a number of ways to do this depending on the screen flow in your app. 有多种方法可以执行此操作,具体取决于应用程序中的屏幕流。 One way to do it would be: 一种方法是:
-create an ivar BOOL shouldReload on view 1 -在视图1上创建一个ivar BOOL应该重新加载
-whenever something happens on view 2 (or anywhere else in the application) that requires a reload of view 1 post a message to [NSNotificationCenter defaultCenter] called something like "View1ShouldReload". -每当需要重新加载视图1的视图2(或应用程序中其他任何地方)上发生任何事情时,都会在[NSNotificationCenter defaultCenter]中发布一条称为“ View1ShouldReload”的消息。
-on load of view 1 set the shouldReload flag to NO and start listening -在视图1的加载上,将shouldReload标志设置为NO并开始监听
-on the notification selector, set shouldReload to YES -在通知选择器上,将shouldReload设置为YES
-on viewDidAppear check if (shouldReload) then do the reload. -on viewDidAppear检查是否(shouldReload)然后重新加载。
There are many other ways to do this (like delegates, singletons, whatever), but this is a simple way to make your app work more efficiently. 还有许多其他方法可以做到这一点(例如代理,单例,等等),但这是使您的应用程序更有效地工作的简单方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.