Re: Cocoa n00b frustrations
Re: Cocoa n00b frustrations
- Subject: Re: Cocoa n00b frustrations
- From: Andy Lee <email@hidden>
- Date: Sat, 07 Jun 2008 23:29:39 -0400
On Jun 7, 2008, at 11:44 PM, Charles Jenkins wrote:
-(BOOL)textShouldBeginEditing:(NSText*)textObject;
-(void)textDidBeginEditing:(NSNotification*)aNotification;
It seems you've set the delegate of the text fields correctly. (To
confirm that they were correctly set by IB, you could NSLog them in -
awakeFromNib.)
The problem is, the above are instance methods of NSTextField, not
delegate methods.
The idea is that at various points in the life of the NSTextField:
(1) It checks whether it has a delegate.
(2) If so, it checks whether the delegate implements such-and-such a
delegate method.
(3) If so, it calls that delegate method.
You have (1), but because you don't have (2), you're not seeing (3).
NSTextField does have delegate methods by virtue of being an
NSControl. If you look at the docs for NSControl you'll see the
following delegate methods, which may be what you want:
- (BOOL)control:(NSControl *)control textShouldEndEditing:
(NSText*)fieldEditor;
- (void)controlTextDidBeginEditing:(NSNotification *)aNotification;
NSLog( [ NSString stringWithFormat: @"Current input source '%s'",
[ name UTF8String ] ] );
As a side note, this would be better written as:
NSLog( @"Current input source '%s'", [ name UTF8String ] );
The first argument to NSLog() is a format string. The way you wrote
it, if [name UTF8String] happens to return @"%s%f%d%x%c", then your
call to NSLog() will have a format string containing five placeholders
with no values being supplied, and your app would crash.
(Full disclosure in case anyone's seen my code: yes, I make this
mistake too. One of these days I'll create a macro that takes an
object and calls NSLog(@"%@", myObject).)
--Andy
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden