• 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
Re: Is NSTableView/NSOutlineView the way to go?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Is NSTableView/NSOutlineView the way to go?


  • Subject: Re: Is NSTableView/NSOutlineView the way to go?
  • From: Andy Lee <email@hidden>
  • Date: Thu, 23 Jun 2005 22:27:27 -0400

On Jun 23, 2005, at 5:56 PM, Mark Dawson wrote:


If it helps any, here's the code I use to put checkboxes in the rows of a table. I do this in the -awakeFromNib method:

    NSButtonCell *checkboxCell =
        [[[NSButtonCell alloc] initTextCell:@""] autorelease];

    [checkboxCell setButtonType:NSSwitchButton];
    [[_frameworksTable
        tableColumnWithIdentifier:_AKCheckboxesColumnID]
        setDataCell:checkboxCell];



A few questions:
(1) _frameworksTable is a private (Apple private) instance variable? Is this different than the outlet I have hooked up to the NSTableView?
(2) What is '_AKCheckboxesColumnID"? I assume I could also use the column title (NSLocalizedStringFromTable(@"ColumnTitle"…)




I copied those lines verbatim from my own code. The idea was that you would substitute your own variables for mine. I was too lazy to replace "_frameworksTable" with "yourTable", and "_AKCheckboxesColumnID" with @"YourColumnID". Sorry about that...


_frameworksTable is an instance variable in my class. It is of type NSTableView. _AKCheckboxesColumnID is a variable I use to hold a column identifier.



(3) What is the id type returned for tableView: objectValueForTableColumn:row: -- a BOOL?



IIRC, you mentioned this method in your original post, so I assumed you knew what it returns. Actually, it's more like you *decide* what it returns. Take a look at the doc for the method. It is in the informal protocol NSTableDataSource. The table view calls it each time it wants to display a cell. The returned value is what gets displayed.


Note that an id cannot be a BOOL. "id" is an object type, "BOOL" is a scalar type.



I think you'd also have to manage the "radioness" of the button cells yourself -- i.e., when the user turns one on, turn off the one that was previously turned on. When the cells are in an NSMatrix, you get this for free, but NSTableView uses one cell instance to draw all the cells in a column. So I think you're going to have to implement - tableView:willDisplayCell:forTableColumn:row:.



So you're saying I'd do something like:
-(void)tableView:(NSTableView *)aTableView willDisplayCell:(id) aCell forTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex
{
if ([[aTableColumn identifier] isEqualToString:@"RadioButtonColumnName"])
{
BOOL isActive = [self isActiveRow:rowIndex inTable:aTableView];
[aCell setState: (isActive ? NSOnState : NSOffState);
}
}




Yup, something like that, assuming you have a method - isActiveRow:inTable: that does what I think you're saying it does.


--Andy




_______________________________________________ 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
References: 
 >Is NSTableView/NSOutlineView the way to go? (From: Mark Dawson <email@hidden>)
 >Re: Is NSTableView/NSOutlineView the way to go? (From: Corbin Dunn <email@hidden>)
 >Re: Is NSTableView/NSOutlineView the way to go? (From: Andy Lee <email@hidden>)
 >Re: Is NSTableView/NSOutlineView the way to go? (From: Mark Dawson <email@hidden>)

  • Prev by Date: Core Data and Drag and Drop
  • Next by Date: Re: NSTableView tableColumn empty?
  • Previous by thread: Re: Is NSTableView/NSOutlineView the way to go?
  • Next by thread: Draw windows offscreen
  • Index(es):
    • Date
    • Thread