Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSControlTextDidChangeNotification fires only once upon setting delegate



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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden

References: 
 >NSControlTextDidChangeNotification fires only once upon setting delegate (From: email@hidden)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.