• 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
NSTableView & subclass of NSButtonCell - odd problem?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSTableView & subclass of NSButtonCell - odd problem?


  • Subject: NSTableView & subclass of NSButtonCell - odd problem?
  • From: Paul Mooser <email@hidden>
  • Date: Sat, 19 Nov 2005 15:37:42 -0800

Hi everyone,

I have been doing some programming which involves a table and a subclass of NSButtonCell. I have noticed in my code that if I try to override the NSButtonCell method drawTitle:withFrame:inView: that the view that is passed into my method is bogus, and will cause an EXC_BAD_ACCESS signal when I call through to super's implementation.

My custom cell class actually at this time contains no instance variables, so I have not had to provide my own implementation of copyWithZone: (for NSCopying support), so I don't think that is causing a problem.

I went ahead and created a sample project to isolate any of the rest of my code from causing this problem. The code below exhibits this issue, and I can only imagine I must be missing something quite obvious.

Any ideas ?

Thanks for your help,

-Paul

@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


  • Follow-Ups:
    • Re: NSTableView & subclass of NSButtonCell - odd problem?
      • From: Daniel Jalkut <email@hidden>
  • Prev by Date: reading NSImage without ColorSync
  • Next by Date: Re: Unable to load palette?
  • Previous by thread: reading NSImage without ColorSync
  • Next by thread: Re: NSTableView & subclass of NSButtonCell - odd problem?
  • Index(es):
    • Date
    • Thread