简体   繁体   中英

reload view did load on returning to view from other tab (iPhone interface builder)

I have 2 views controlled by a tab bar controller.

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?

EDIT: and the answer is: viewWillAppear instead of viewDidLoad i think (can't answer own question for 8 hours)

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. 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

-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".

-on load of view 1 set the shouldReload flag to NO and start listening

-on the notification selector, set shouldReload to YES

-on viewDidAppear check if (shouldReload) then do the reload.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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