• 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
NSCell problems again!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSCell problems again!


  • Subject: NSCell problems again!
  • From: Gore <email@hidden>
  • Date: Thu, 28 Mar 2002 10:50:16 +0200

The goal is to create a cell that I will use with NSOutlineView. The cell is a NSSwitchButton type because I want the cell to both be able to display a checkbox and a ttextfield. To display the cell is no problem, but to both be able to edit the state of the checkbox and the string in the textfield is a big problem. Here are some code from my application that I have been experimenting with, I HAVE NO IDEA TO DO THIS!? so please help.

The creation of the cell in -(void)awakeFromNib:
-----------------------------------------------------------------------------------------
StatusCell *statusCell = nil;

tableColumn = [mainOutlineView tableColumnWithIdentifier: @"NameAndStatus"];
statusCell = [[[StatusCell alloc] init] autorelease];
[statusCell setEditable: YES];
[statusCell setSendsActionOnEndEditing: YES];
[statusCell setButtonType: NSSwitchButton];
[statusCell setAllowsMixedState: YES];
[tableColumn setDataCell: statusCell];

The interface of StatusCell:
-----------------------------------------------------------------------------------------
@interface StatusCell : NSButtonCell
{
}

This is how the implementation of StatusCell looks like right now:
-----------------------------------------------------------------------------------------
- (id <NSCopying>)objectValue
{
return [NSArray arrayWithObjects: [super title], [NSNumber numberWithInt: [super state]], nil];
}

- (void)setObjectValue:(id <NSCopying>)obj
{
if ([(id)obj isKindOfClass: [NSString class]]) {
[super setTitle: obj];
} else if ([(id)obj isKindOfClass: [NSNumber class]]) {
[super setState: [(NSNumber*)obj intValue]];
}
}

- (void)editWithFrame:(NSRect)aRect inView:(NSView *)controlView editor:(NSText *)textObj delegate:(id)anObject event:(NSEvent *)theEvent
{
NSRect textFrame, statusFrame;

NSDivideRect (aRect, &statusFrame, &textFrame, 20, NSMinXEdge);

[super editWithFrame: textFrame inView: controlView editor:textObj delegate:anObject event: theEvent];
}

- (void)selectWithFrame:(NSRect)aRect inView:(NSView *)controlView editor:(NSText *)textObj delegate:(id)anObject start:(int)selStart length:(int)selLength
{
NSRect textFrame, statusFrame;

NSDivideRect (aRect, &statusFrame, &textFrame, 20, NSMinXEdge);

[super selectWithFrame: textFrame inView: controlView editor:textObj delegate:anObject start:selStart length:selLength];
}

- (NSSize)cellSize
{
NSSize cellSize = [super cellSize];
cellSize.width += 20;
return cellSize;
}

This is how the cell is displayed in the NSOutlineView:
-----------------------------------------------------------------------------------------
- (void)outlineView:(NSOutlineView *)olv willDisplayCell:(NSCell *)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item {
NSString *ident = [tableColumn identifier];

if ( [ident isEqualToString: @"NameAndStatus"] ) {
[cell setObjectValue: [NSNumber numberWithInt: [item itemIsSelected]]];
[cell setObjectValue: [item name]];
}
}

This is how I think editing of the values should be done (doesn't work):
-----------------------------------------------------------------------------------------
- (void)outlineView:(NSOutlineView *)outlineView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
{
NSString *ident = [tableColumn identifier];

if ( [ident isEqualToString: @"NameAndStatus"] ) {
[(DataSourceItem *)item setName: [object objectAtIndex: 0]];
[(DataSourceItem *)item setItemIsSelected: [[object objectAtIndex: 1] intValue]];
}


So, how do I seperate the editing of the checkbox and the editing of the textfield, because if I try to double click to edit the textfield the checkbox value will change too. please help.

// Gore
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Re: NSTableView in a sheet
  • Next by Date: Re: Document Loading Problem
  • Previous by thread: Re: Problems with NSString: initWithCString
  • Next by thread: Fwd: Undeliverable mail for mailto:email@hidden
  • Index(es):
    • Date
    • Thread