Re: NSTableView & different columns
Re: NSTableView & different columns
- Subject: Re: NSTableView & different columns
- From: mmalcolm crawford <email@hidden>
- Date: Sat, 2 Jul 2005 20:33:14 -0700
On Jul 2, 2005, at 6:19 PM, Dave Hersey wrote:
In your PersonObject from above, you'd now create a checkbox object
at init
time.
[...]
@interface PersonObject : NSObject
{
NSButtonCell *m_checkbox;
Don't do this!
See <http://developer.apple.com/documentation/Cocoa/Conceptual/
AppArchitecture/Concepts/MVC.html>, <http://developer.apple.com/
documentation/Cocoa/Conceptual/CocoaDesignPatterns/index.html> etc.
There is almost no reason why a model object should keep a view
object like a control cell as one of its variables. All that's
needed is to:
1. Set the cell for the column in the table view.
2. In the ... objectValueForTableColumn ... method, return a value
that's appropriate for the cell (in this case, an NSNumber).
On 7/2/05 7:16 PM, "Sanri Parov" <email@hidden> wrote:
the example was pretty good, but there's a point: you use an array,
which is a very good and common way to treat datas.
In my case, I'd like to set the first column with a progressive row
number and the second one with a checkbox that's set
on the checked position if a file exists in a certain location.
I presume that the file is based on an attribute of the model object
(such as a 'fileName' variable)? You might do something like this:
- (id) tableView: (NSTableView *) tableView
objectValueForTableColumn: (NSTableColumn *) tableColumn
row: (int) rowIndex
{
if ([[tableColumn identifier] isEqualToString:@"fileExists"])
{
NSString *filePath = [[sourceArray objectAtIndex:rowIndex]
fileName];
// If appropriate, do whatever else is necessary to get the
complete path
BOOL fileExists = [[NSFileManager defaultManager]
fileExistsAtPath:filePath];
return [NSNumber numberWithBool:fileExists];
}
// implementation continues ...
mmalc
_______________________________________________
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