Update view under a modal view form sheet

911 views Asked by At

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?

2

There are 2 answers

1
Nick Lockwood On BEST ANSWER

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.

3
Shubhank On

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

You can then change its background using setBackgrouncolor method