• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Simple bindings problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Simple bindings problem


  • Subject: Simple bindings problem
  • From: Martin Linklater <email@hidden>
  • Date: Sat, 5 Jan 2008 09:58:32 +0000

I'm writing some very simple applications to lear how bindings work and I've hit upon another problem that I can't figure out. Hopefully it's not some dismal typo on my part 8).

I have a simple application with two NSTextViews - one for displaying an integer value and one for displaying an NSString value. My AppController has one int member and one NSString member (code below). I have an NSObjectController which has it's content bound to my AppController. I have bound both of the NSTextViews to my Controller and set their Controller Key to 'selection' and their Model Key Path to the names of my AppController member variables.

The problem I am having is that my integer binding is working fine - updates from both the model and the view are propigated by the binding. But my NSString member is causing a runtime crash:

2008-01-05 09:45:19.188 BindingsTest[9890:813] *** -[NSTextField copyWithZone:]: unrecognized selector sent to instance 0x12bc50
2008-01-05 09:45:19.189 BindingsTest[9890:813] An uncaught exception was raised
2008-01-05 09:45:19.190 BindingsTest[9890:813] *** -[NSTextField copyWithZone:]: unrecognized selector sent to instance 0x12bc50
2008-01-05 09:45:19.190 BindingsTest[9890:813] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** - [NSTextField copyWithZone:]: unrecognized selector sent to instance 0x12bc50'


Yet both of the bindings are set up the same in IB...

When I put breakpoints on the setter and getter methods for the NSString my code seems to be initialising my AppController fine and setting the member variables, but then immediately tries to access a different instance for some reason (the 'self' ptr changes). This is when the crash happens. Problem is that I have no idea why my code is setting up a correct instance of my AppController and then trying to read the contents of an invalid instance of my AppController class. Can anyone help ? Thank you.

Here is the code for my AppController:

---- header

#import <Cocoa/Cocoa.h>

@interface AppController : NSObject {
	int	testInt;
	NSString* insertText;
}

- (void)setTestInt:(int)intIn;
- (int)testInt;

- (NSString*)insertText;
- (void)setInsertText:(NSString*)insertIn;

@end

---- implimentation

#import "AppController.h"

@implementation AppController

- (id)init
{
	if( self = [super init] )
	{
		[self setTestInt:10];
		[self setInsertText:@"five"];
	}
	return self;
}

- (void)setTestInt:(int)intIn
{
	NSLog( @"value set to %d", intIn);
	testInt = intIn;
}

- (int)testInt
{
	NSLog(@"testInt read");
	return testInt;
}

- (NSString*)insertText
{
	NSLog(@"reading insertText");
	return insertText;
}

- (void)setInsertText:(NSString*)insertIn
{
	NSLog(@"setting insertText");
	if( insertText != insertIn )
	{
		[insertText release];
		insertText = insertIn;
		[insertText retain];
	}
}

@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


  • Follow-Ups:
    • Re: Simple bindings problem
      • From: Martin Linklater <email@hidden>
  • Prev by Date: Re: thread protocol modifiers
  • Next by Date: Re: Trapping user shutdown/logout/restart in Cocoa/Foundation tool
  • Previous by thread: Re: Assigning Binary Data From Network To Variables
  • Next by thread: Re: Simple bindings problem
  • Index(es):
    • Date
    • Thread