UISplitViewController - Best design pattern for communicating between view controllers

I'm using a UISplitViewController in my app for the first time. The master view controller is a table view controller, and the detail view controller is just a plain view controller.

For communication from master to the detail I set the detail as a delegate of the master. But I also need the master to be able to respond to changes in the detail (The corresponding table view cell's content would update to reflect the change.)

Is it OK for the master to also be a delegate of the detail? Or is this bad programming practice? Is there a better approach for this?

Thanks for any suggestions.

Answers


You could provide a delegate protocol specific to your model, which is shared by both your controllers. This protocol could have methods such as itemContentDidChange:withIndex: and so on, providing listeners with info on what's changed in the model. If you register both controllers as delegates for your shared model, both implementing this shared protocol, the cross-controller dependency would be removed without introducing any new dependencies.

However, this is only my opinion, which is rather subjective. Your approach is perfectly fine, too - I think it is absolutely OK for the master to be a delegate of the detail at the same time as the detail is a delegate of the master. It is better than giving each controller a pointer to the other one, because you do not need to think about retain cycles.


Need Your Help

WPF TextBox validation removes 0s before other digits

c# wpf validation textbox number-formatting

I'm implementing a validation rule for a property of type double bound to a TextBox. The problem is that when I enter a 0 in the decimal digits, if the resulting number is accepted by the rule, WPF