Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
neftali
5,294 PointsNSNotificationCenter and UIPicker on 2 tabbed based app
I have a 2 tabbed based app. Second tab has a UIPickerView. First tab has a Tap screen method which executes a specific or calls a specific method in firstViewController according to what has been selected from the UIpicker and proceeds to the method it is matching a selection from UIPIckerView. How can i do this with a NSNotificationCenter properly ? i've tried deegates, Segues and even the Singleton ways but no result which leaves me at NSNotificationCenter to radio in whatever is been selected and broadcasted to the firstViewController.
1 Answer
John W
21,558 PointsYou don't use any delegate for NSNotificationCenter. What you do is register your object as an observer using a name/keyword. And then your event-triggering object would post a notification using the same keyword. At that point, all registered observers (with the same keyword) would trigger their respective method/block.
Like NSHipster said, notification center is one of those powerful features of Objective-C that is under-documented and awkward. (long history too) http://nshipster.com/nsnotification-and-nsnotificationcenter/
Another solution would be to access the first view controller from the second view controller using [self.tabviewcontroller.viewcontrollers objectAtIndex:0]. This way, you can set up a property, and access it this way.