UINavigationController viewController intra communication
Whats the best way for UIViewControllers that are pushed onto a UINavigationController to communicate with each other?
Method chaining开发者_StackOverflow back up to the root most parent view controller?
Connecting references to other view controllers w/ IB?
First you should be asking why they're talking to each other rather than talking to the Model layer and letting other View Controllers watch the Model layer. Lots of chatter between view controllers is generally a sign of poor design, but it does come up sometimes.
Generally speaking, I recommend loose coupling, often best implemented in NSNotifications.
NSNotifications are inappropriate if you need two-way communication, though in that case you likely really have a design error. But if it were a good design despite that, I would consider the case of VCs that need to coordinate with all the VCs versus only with their parents. In the former case, I'd subclass the Navigation Controller to provide coordination. In the latter case, I'd use a parent pointer.
But the most common case for a strong need of VC chatter is that your view controllers are doing something that should be done at the Model layer.
I was actually typing the exact mesasge Rob Napier typed, when SO gave me an answer notification (thanks rob ;).
Rob left out Delegation. You might want to take a look at that as well.
精彩评论