Question

So, I have a view with the button. I tap on this button and modal view with style "Form Sheet" appears. There I make a change, and because of this change the background color of our first view with button (now behind of modal view) must be changed. Question is, how to do that?

Was it helpful?

Solution

The viewcontroller of the underlying page is still there and can still execute code on its view. The view may be unloaded because it's not on screen, but viewcontroller.view is a lazy contructor, so setting properties on it will cause it to be re-created anyway.

The trick is how to communicate with the underlying view controller. A good way to handle cross-viewcontroller communication is to post an NSNotification using NSNotificationCenter.

Set your background viewcontroller to observe a notification called something like "BackgroundColorChangedNotification" and then post a notification with that name from your modal form viewcontroller.

The advantage of this approach is that if any other controllers in the app need to know about this change, they can all just register for the notification, and none of these controllers need to know anything about each other, so your code is nicely decoupled.

OTHER TIPS

Self.view.parentView will let you access the first view

You can then change its background using setBackgrouncolor method

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top