Re: NSControlTextDidChangeNotification fires only once upon setting delegate
Re: NSControlTextDidChangeNotification fires only once upon setting delegate
- Subject: Re: NSControlTextDidChangeNotification fires only once upon setting delegate
- From: "stephen joseph butler" <email@hidden>
- Date: Fri, 28 Sep 2007 21:57:20 -0500
On 9/28/07, email@hidden <email@hidden> wrote:
> Am I doing something wrong in my delegate that keeps subsequent
> notifications from firing? I have tried google searches and read the
> NSTextView class documentation, and I'm stuck.
>
> Is this the wrong approach? Any suggestions are welcome.
You're thinking about this too hard. Here's silly code that works,
just set MyController as the delegate of NSMatrix:
#import <Cocoa/Cocoa.h>
@interface MyController : NSObject
{
}
- (void) controlTextDidChange:(NSNotification*)aNotification;
- (NSArray*) control:(NSControl*)control
textView:(NSTextView*)textView
completions:(NSArray*)words
forPartialWordRange:(NSRange)charRange
indexOfSelectedItem:(int*)index;
@end
@implementation MyController
/* delegates automatically get this message, you don't need
* to register for it seperately */
- (void) controlTextDidChange:(NSNotification *)aNotification
{
[[[aNotification userInfo] objectForKey:@"NSFieldEditor"] complete:nil];
}
/* The NSMatrix is a delegate of the field editor, and it passes this message
* on to its delegate. So when you changed the delegate of the field editor,
* you unwittingly broke what NSMatrix expects to happen. Which is why things
* stopped working */
- (NSArray*) control:(NSControl*)control
textView:(NSTextView*)textView
completions:(NSArray*)words
forPartialWordRange:(NSRange)charRange
indexOfSelectedItem:(int*)index
{
NSMutableArray *rv = [NSMutableArray array];
NSString *text = [textView string];
[rv addObject:[text stringByAppendingString:text]];
[rv addObject:[text stringByAppendingString:
[text stringByAppendingString:text]]];
[rv addObject:[text stringByAppendingString:
[text stringByAppendingString:
[text stringByAppendingString:text]]]];
*index = -1;
return rv;
}
@end
_______________________________________________
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