Custom Field Editor Problem
Custom Field Editor Problem
- Subject: Custom Field Editor Problem
- From: John Nairn <email@hidden>
- Date: Tue, 2 Feb 2010 11:02:55 -0800
I copied code from Cocoa documentation to create a custom field
editor. It gets created OK and seems to work, but always crashes when
the the window closes with the message
Program received signal: “EXC_BAD_ACCESS”.
sharedlibrary apply-load-rules all
I created the custom editor in the window controller using code from
Apple:
- (id)windowWillReturnFieldEditor:(NSWindow *)sender toObject:(id)
anObject
{
if([anObject isKindOfClass:[NSTextField class]])
{ if(!customEditor)
{ customEditor=[[BrowserFieldEditor alloc] init];
[customEditor setFieldEditor:YES];
}
return customEditor;
}
return nil;
}
When the window controller is deallocated, it calls
[customEditor dealloc];
Finally, the entire custom editor, which is NSTextView subclass, is
@implementation BrowserFieldEditor
- (id)init
{ if(self=[super init])
{ NSLog(@"init field editor");
}
return self;
}
- (void)dealloc
{ NSLog(@"dealloc field editor");
[super dealloc];
}
@end
The "init field editor" message appears when created and the "dealloc
field editor" appears just before the crash. If I change the window
controller to not release the custom editor, the crash stops, but the
"dealloc field editor" message never appears (i.e., a memory leak).
Also the Apple documentation explicitly says:
The custom field editor should be released in an appropriate place,
such as the dealloc method of the window delegate object (if the field
editor was never instantiated, therelease message has no effect and is
harmless).
------------
John Nairn
http://www.geditcom.com
Genealogy Software for the Mac
_______________________________________________
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