Re: NSTableView & subclass of NSButtonCell - odd problem?
Re: NSTableView & subclass of NSButtonCell - odd problem?
- Subject: Re: NSTableView & subclass of NSButtonCell - odd problem?
- From: Daniel Jalkut <email@hidden>
- Date: Sat, 19 Nov 2005 19:37:00 -0500
Hi Paul!
Your problems are based in the method declaration of "drawTitle..."
I'm not really familiar with this method, because it's new in 10.4
and I haven't looked at it yet. But it looks like there is either a
header file or a documentation bug, because the documentation
describes this method as returning void, while the header file
defines it as returning an NSRect.
Without proper documentation, it's hard to know what the "right"
thing to do is, here. But I will say that replacing your drawTitle
method with this makes the crash go away:
- (NSRect) drawTitle:(NSAttributedString *)title withFrame:(NSRect)
frame inView:(NSView *)controlView {
[super drawTitle:title withFrame:frame inView:controlView];
return frame;
}
I suspect that the ObjC glue generated for a "void return" and for a
"value return" are different. So the glue has a totally different
idea of what kind of function you're providing, and somehow screws up
the arguments.
Daniel
On Nov 19, 2005, at 6:37 PM, Paul Mooser wrote:
@interface Cell : NSButtonCell {
}
@end
@implementation Cell
- (id)init {
self = [super initTextCell:@"Ready"];
[self setButtonType:NSSwitchButton];
return self;
}
// This next method causes a crash! controlView is a bad address
- (void)drawTitle:(NSAttributedString *)title withFrame:(NSRect)
frame inView:(NSView *)controlView {
[super drawTitle:title withFrame:frame inView:controlView];
}
@end
@interface Controller : NSObject {
NSMutableArray *_array;
IBOutlet NSTableView *_tableView;
}
@end
@implementation Controller
- (void)awakeFromNib {
NSNumber *number = [NSNumber numberWithBool:NO];
_array = [[NSMutableArray
arrayWithObjects:number,number,number, nil] retain];
Cell *cell = [[Cell alloc] init];
NSTableColumn *column = [_tableView
tableColumnWithIdentifier:@"1"];
[column setDataCell:cell];
[cell release];
// setup the data source:
[_tableView setDataSource:self];
}
// NSTableDataSource
- (int)numberOfRowsInTableView:(NSTableView *)aTableView {
return [_array count];
}
- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:
(NSTableColumn *)column row:(int)rowIndex {
id identifier = [column identifier];
if ( [identifier isEqual:@"1"] ) {
return [_array objectAtIndex:rowIndex];
}
else
return nil;
}
- (void)tableView:(NSTableView *)aTableView setObjectValue:(id)
object forTableColumn:(NSTableColumn *)column row:(int)rowIndex {
id identifier = [column identifier];
if ( [identifier isEqual:@"1"] ) {
[_array replaceObjectAtIndex:rowIndex withObject:object];
}
}
@end
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden