Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jul 9, 2009, 09: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, 10: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, 07: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, 01: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, 04: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, 07: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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
How to convince my parents to let me buy a 17" MacBook Pro Ulf1103 Buying Tips and Advice 58 Nov 27, 2013 11:45 AM
How to remove space between window and dock? StephenHuang Mac Basics and Help 13 Aug 25, 2013 09:37 AM
Tutorial: How to get PCSX2 to run on Mac (without BootCamp) Mirrors Mac Applications and Mac App Store 22 Jun 14, 2013 08:19 PM
[HOW TO] DIY iPhone 4 Swivel Car Mount QuarterSwede iPhone Accessories 13 Mar 8, 2011 02:51 PM
PHP - How to pass arrays between pages? mmmdreg Web Design and Development 4 May 8, 2007 02:44 AM


All times are GMT -5. The time now is 07:39 AM.

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

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