On Wednesday, January 29, 2003, at 08:38 PM, Rich Morin wrote:
There's a design pattern to method names - each part of the method name describes the argument that follows it. Also, this method expects four arguments, and you've only passed three.My suspicion is that I need to put something like the following in MyWindowController.pm's "new" method:my $dnc = NSNotificationCenter->defaultCenter(); $dnc->addObserver_selector_name_object( NSTableViewSelectionDidChangeNotification, 'Access row selected', ''); but that doesn't do anything. Help?
What you'd want to do is this. Let's assume you want to call a MyWindowController method named "tableViewSelectionDidChange" in response to an "NSTableViewSelectionDidChangeNotification". (I like to name the methods that respond to notifications differently from the notification names themselves, as it's easy to confuse them if they share the same name. There's no technical reason they can't be named the same, I just find it easier.)
$dnc->addObserver_selector_name_object(
$self,
"tableViewSelectionDidChange:",
"NSTableViewSelectionDidChangeNotification",
undef
);
Two things to note in the above example: The first is that ObjC isn't as flexible as Perl with respect to method arguments. A method that wants four arguments won't work with three. (Adding code to CB that pads any missing arguments with nils is an interesting idea, though...)
The other point to note is the colon at the end of the selector string - it's not a typo. Selectors use colons to indicate arguments. For example, the selector for the registration method is "addObserver:selector:name:object:". Note that, when it's called from Perl, the colons are replaced with underscores - that's because colons aren't valid parts of method names in Perl. Also note that there's a trailing colon, but no trailing underscore - that's because having to append an underscore to every method call that takes one or more arguments would be a pain in the butt, and result in ugly code. :-)
Another interesting idea for a future version of CB is to translate Perl method names to their ObjC equivalents, when they're passed as selectors...
sherm--
UNIX: Where /sbin/init is Job 1.
