Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Richard Birkett

macrumors member
Original poster
Aug 21, 2011
30
0
I'm not new to this, but I've taken a break from programming. I say that because it sounds stupid...

My textfield is sending a notification twice! Worse than that, it types the letter twice! Without anything set up it types and acts normally, plain old text field. If I set the appDelegate to the text field's delegate using IB and then use the following code:

Code:
#import <Cocoa/Cocoa.h>
#import "RBMExpression.h"

@interface RBMAppDelegate : NSObject <NSApplicationDelegate>

- (void)controlTextDidChange:(NSNotification *)aNotification;

@property (strong) IBOutlet NSTextField *myTextField;
@property (assign) IBOutlet NSWindow *window;

@end


#import "RBMAppDelegate.h"

@implementation RBMAppDelegate

@synthesize myTextField = _textField;
@synthesize window = _window;

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
		// Insert code here to initialize your application
}

- (void)controlTextDidChange:(NSNotification *)aNotification
{
	NSString *theString = [_textField stringValue];
	[RBMExpression expressionWithString:theString];
}
@end

It starts double typing each character and sending the notification twice.

Any help appreciated!!!

Richard
 
If you comment out the body of your controlTextDidChange: but still leave the delegate connection in place in IB, do you still get this behaviour?
Code:
- (void)controlTextDidChange:(NSNotification *)aNotification
{
	[COLOR=blue]NSLog(@"%s: aNotification=%@", __PRETTY_FUNCTION__, aNotification);[/COLOR]
[COLOR=blue]/*[/COLOR]
	NSString *theString = [_textField stringValue];
	[RBMExpression expressionWithString:theString];
[COLOR=blue]*/[/COLOR]
}
 
Hi,

Sorry, panic over, thanks for replying. It was strange to be fair, it was due to an error in expressionWithString: from trying to get an out of bounds substring of an NSString (using a bad for loop and substringWithRange:), I still don't understand fully but it was logging an error amongst my other logs, and for some unknown reason it had to repeat the notification! Fixing the small error fixed this problem.

Thanks,

Richard
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.