Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Dec 15, 2011, 03:52 PM   #1
Richard Birkett
macrumors member
 
Join Date: Aug 2011
NSTextField, Help!

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
Richard Birkett is offline   0 Reply With Quote
Old Dec 15, 2011, 06:46 PM   #2
jiminaus
macrumors 65816
 
Join Date: Dec 2010
Location: Sydney
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
{
	NSLog(@"%s: aNotification=%@", __PRETTY_FUNCTION__, aNotification);
/*
	NSString *theString = [_textField stringValue];
	[RBMExpression expressionWithString:theString];
*/
}
jiminaus is offline   0 Reply With Quote
Old Dec 15, 2011, 07:27 PM   #3
Richard Birkett
Thread Starter
macrumors member
 
Join Date: Aug 2011
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
Richard Birkett is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Using NSTextField to save text into cutom format at a temp location SirFurtWiggle Mac Programming 1 Apr 24, 2014 09:16 AM
How do you set cursor initial cursor position and NSTextField bounds? DavidBlack Mac Programming 3 Mar 1, 2014 11:46 AM
NSTextField focus don't work if is added programmatically Ivang Mac Programming 5 Oct 1, 2013 09:27 AM
Adding a percent in a NSTextField jweinraub Mac Programming 13 May 12, 2013 11:27 PM
Have a NSTextField Popup on button click hightekrednek Mac Programming 0 Aug 7, 2012 07:41 PM

Forum Jump

All times are GMT -5. The time now is 07:30 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps