I have been using Protocols and Delegates for a couple of weeks now and have gotten used to passing data from a subview to its parent view no problem.
However I am now trying to pass some data with protocols and delegates from a sub subview to its parent view on the navigation stack.
i.e.
view 0 - to here, missing view 1
-- view 1
--- view 3 - pass from here
however the problem being is setting up that parent view as a delegate I cannot seem to find a way to do it. I have set it like this
SubResultViewController *subResultViewController = [[SubResultViewController alloc] init];
[subResultViewController setDelegate:self];
Then I set everything up in that subResultViewController I dont get any errors when I execute all the code how ever when I put a break point into the receiving method of the delegate in the main view where I am passing everything to it just never gets accessed..
I am hoping I can get some help with using protocols and delegates in this way (over multiple views on the navigational stack)
any help would be greatly appreciated.
The problem with passing delegates from views is that the viewController has already been loaded once, so doing this:
is initializing a new SubResultViewController object, not the one already loaded(initialized).
You have to somehow pass the receiving viewController to the view that you want to send the message from.This is where NSNotification’s come in handy. You can set your receiving view controller as a listener(observer) for the notification, then anytime a notification is posted with the same “name”, any thing listening will get the message.Once I learned how to use the NotificationCenter It change how I was able to communicate between views/classes.
http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSNotificationCenter_Class/Reference/Reference.html