I’m working on an iPad app has many pages for users to browse through. I’m implementing the functionality for users to ‘favorite’ a page so they can revisit it later.
I’m writing a Favorites class that will manage a list of the user’s favorite pages. When a user presses the ‘favorite’ button, it will call either the addFavorite: or removeFavorite: method on the Favorites class. The input seems simple enough.
My question is: what’s the best way to propagate that state-change event out to all my views? I have many redundant ‘favorite’ indicators scattered throughout the app, and they all need to be kept in sync. For instance, if the user favorites Pink Floyd in one view (changing the star from gray to yellow), all the other views that link to Pink Floyd need to display yellow stars next to the link instead of gray ones.
It’s my understanding that there are lots of ways to do this using Objective-C notifications. I’m just looking for a clean and maintainable one. What has worked for you in the past? Thanks for your time.
Check up on
NSNotificationCenterandNSNotification. I use notifications quite regularly especially if there is more than one party interested in the shared information making the delegate pattern difficult. The main issue with notifications I’ve run into is when subscribing UITableViewCell’s to a notification: avoiding that dequeued cells respond to the notification.