Re: reading selectedItem from within dataCellForRow?
Re: reading selectedItem from within dataCellForRow?
- Subject: Re: reading selectedItem from within dataCellForRow?
- From: Yann Bizeul <email@hidden>
- Date: Tue, 5 Jun 2007 08:15:33 +0200
My problem is that I want to build the next NSPopUpButtonCell pending
upon the selection of the top NSPopUpButtonCell. So if popupButtonCell
on row 0 has item A selected, then popupButtonCell on row 1 should
only contain and show 2 items (A-B), otherwise, it might list items
A-C.
The thing is a TableView uses a single instance of NSCell to display
content in a columns, this instance is set with setDataCell: for
example, and it is returned when you call dataCellForRow:r on super
(default implementation just returns "dataCell"
Since there is one instance, you can't really modify its structure
and expect it to behave differently when it is displayed.
Try to allocate a new Cell and return that instead of calling the
column's data cell
This thread has interesting informations too :
http://www.cocoabuilder.com/archive/message/cocoa/2002/12/28/71140
Regards,
Yann Bizeul - yann at tynsoe.org
Cocoa Developer
Tynsoe Projects
BuddyPop - GeekTool - SSH Tunnel Manager - ...
http://projects.tynsoe.org/
Le 5 juin 07 à 04:44, William Zumwalt a écrit :
I have a class subclassed from NSTableColumn which overrides
dataCellForRow: like what's listed below.
My problem is that I want to build the next NSPopUpButtonCell pending
upon the selection of the top NSPopUpButtonCell. So if popupButtonCell
on row 0 has item A selected, then popupButtonCell on row 1 should
only contain and show 2 items (A-B), otherwise, it might list items
A-C.
But I don't know how to make that decision from within this method
because I can't seem to get a handle on the data from here.
- (id) dataCellForRow:(int) row
{
id textCell = [super dataCellForRow:row];
NSPopUpButtonCell *pubCell;
if (row == 0 || row == 1) {
pubCell = [[NSPopUpButtonCell alloc] init];
[pubCell setBordered:NO];
[pubCell setPullsDown:NO];
[pubCell setFont:[NSFont labelFontOfSize:[NSFont
smallSystemFontSize]]];
[pubCell setControlSize:NSMiniControlSize];
[pubCell setAlignment:NSLeftTextAlignment];
[pubCell setEditable:YES];
}
if (row == 0) {
[pubCell addItemWithTitle:@"selection A"];
[pubCell addItemWithTitle:@"selection B"];
}
else if (row == 1) {
// if "selection A" in row 0 has A selected, then I list 2 items.
[pubCell addItemWithTitle:@"selection A"];
[pubCell addItemWithTitle:@"selection B"];
// otherwise, I might list all 3 items if I could see
// what is selected from here.
[pubCell addItemWithTitle:@"selection C"];
}
else if (row == 2) {
[textCell setEditable:NO];
[textCell setTextColor:[NSColor blackColor]];
}
if (row == 0 || row == 1) {
// these rows are popupButtonCell's
return pubCell;
}
// all other rows are NSTextFieldCell's
return textCell;
}
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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