views:

652

answers:

3

I wonder what is the proper way to get back some message from a child view.

I have a object that is edited in the child view. I wanna see in the TableView their modifications.

However, I don't know a clean way to do it (I don't like a singleton here).

Is possible get notified when the Child view dissapear and get some info on that?

+2  A: 

You can use the UIViewController notifications viewWillDisappear: and viewDidDisappear: to be notified right before a certain UIView is about to disappear and right after it disappears respectively. Note that most of the various UIKit objects (including UITableView) are subclasses of UIView.

Adam Rosenfield
+1  A: 

IMHO, the "correct" way would be to implement a custom protocol in the view's controller (probably navigation controller in your case) or the application delegate and have the child view communicate using it when it gets the viewWillDisappear and/or viewWillDisappear notifications (as mentioned in Adam's reply). Similarly, in the parent view you can refresh the necessary information in the viewWillAppear handler.

This way, the parent view is getting its data from the delegate and not directly from a specific child view, which maintains MVC in your design.

codelogic
A: 

You could also issue a notification (using NSNotificationCenter) that the parent would be subscribed to listen for - that has the side benefit that other classes could be notified as well.

But if it's a pretty strict relationship where only the sub view and master table will care, you probably should set your table view controller as a delegate of the subview and have the subview call the delegate directly (a protocol as mentioned is a good idea for something like this).

Kendall Helmstetter Gelner