Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jul 9, 2009, 10:32 AM   #1
mpemburn
macrumors member
 
Join Date: Jan 2008
Location: Bel Air, MD USA
How to pass messages between windows

Hi,

I'm sure that I'm not getting this because I'm thinking about it the wrong way ;-)

I need to alert my main window controller that things have changed when the user makes a change in the preferences pane. Is this possible?


Thanks!

-- Mark
mpemburn is offline   0 Reply With Quote
Old Jul 9, 2009, 11:55 AM   #2
kainjow
Moderator emeritus
 
kainjow's Avatar
 
Join Date: Jun 2000
Use NSNotifications, or KVO if this is a change in a direct preference value which is bound to NSUserDefaultsController.
kainjow is offline   0 Reply With Quote
Old Jul 9, 2009, 08:17 PM   #3
mpemburn
Thread Starter
macrumors member
 
Join Date: Jan 2008
Location: Bel Air, MD USA
Thanks, I'll give it a look!

-- Mark
mpemburn is offline   0 Reply With Quote
Old Jul 10, 2009, 02:49 PM   #4
larkost
macrumors 6502a
 
Join Date: Oct 2007
You don't have to be using NSUserDefaultsController to use KVO, you just have to make sure to use the get/set convention in your method names, and as long as you inherit from NSObject everything should be setup fine to use KVO.
larkost is offline   0 Reply With Quote
Old Jul 10, 2009, 05:04 PM   #5
isharan
macrumors member
 
Join Date: Jun 2009
Definitely NSNotification.

Code:
[[NSNotificationCenter defaultCenter] postNotification:@"MyVariableChanged"];
isharan is offline   0 Reply With Quote
Old Jul 13, 2009, 08:43 AM   #6
mpemburn
Thread Starter
macrumors member
 
Join Date: Jan 2008
Location: Bel Air, MD USA
Once I understood what was required, this was pretty easy to implement. To save you some trouble if you've found this thread while searching for help doing the same thing:

In my main controller, I added the following line to awakeFromNib:

Code:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(preferencesChanged) name:@"PreferencesChanged" object:nil];
Since it will be looking for a method called "preferencesChanged", I also added this to the main controller:

Code:
- (void) preferencesChanged; {
	/*
	Code to deal with changed preferences goes here
	*/
}
Finally, in my Preferences controller, I added this line to the code that applies changes after the user has made their choices:

Code:
[[NSNotificationCenter defaultCenter] postNotificationName:@"PreferencesChanged" object:nil];
So, when the code hits the "postNotificationName" line, it drops a message named "PreferencesChanged" into the Notification dispatch table. The observer (in the main controller) is primed to look for any notifications named "PreferencesChanged", and when one is found, it redirects processing to the preferencesChanged method.

-- Mark
mpemburn is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Any Windows App that works with iPhone Messages BryanSchmiedele Windows, Linux & Others on the Mac 2 Dec 14, 2013 09:42 PM
Phone not notifying messages? late messages? worth a new device? CBillups1 iPhone 4 Aug 14, 2013 12:02 PM
Project Amy Allows Users to Send App.net Private Messages via Messages for OS X MacRumors Mac Blog Discussion 6 Mar 5, 2013 11:31 AM
Mountain Lion Messages app wont let me send text messages EstrlM3 Mac Applications and Mac App Store 7 Jul 28, 2012 01:11 PM

Forum Jump

All times are GMT -5. The time now is 05:10 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC