Question

I'm having hard time understanding how to implement view-based table in cocoa. Right now I have working implementation of old-fashioned cell-based table. As I figured out, just dragging the NSTableCellView onto my columns in a NIB file won't make my table view-based :)

I read through this article: http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/TableView/TableViewOverview/TableViewOverview.html

But still clueless...for some reason my tableView:viewForTableColumn:row: method is not getting hit.

Can some one give me step by step explanations on how can I convert my cell-based table to view-based?

In my cell-based table I have:

// .h
#import "ObjectClass.h"
#import "ObjectTable.h"

@interface ObjViewController : NSObject <NSTableViewDataSource, NSTableViewDelegate>
{
    IBOutlet ObjectTable *objectTable;
    NSMutableArray *list;
    ObjViewController *current;
}  

//.m
#import "ObjViewController.h"

@implementation ObjViewController

-(id)init
{
   self = [super init];
   if (self)
   {
       current = self;
       list = [[NSMutableArray alloc] init];
   }

   return self;
}

- (NSInteger) numberOfRowsInTableView:(NSTableView *)tableView
{
    return [list count];
}

-(id) tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn
                                                               row:(NSInteger)row
{
    ObjectClass *obj = [list objectAtIndex:row];

    NSString *identifier = [tableColumn identifier];

    return [obj valueForKey: identifier];
}

// .h
@interface ObjectClass : NSObject
{
}
@property int categoryID;
@property int oID;
@property NSString *name;

@end

Thank you!

Was it helpful?

Solution

The method

tableView:viewForTableColumn:row:

Is from the NSTableViewDelegate protocol and once implemented will make the NSTableView a view-based table. From the code above, the view controller is not conforming to the NSTableViewDelegate protocol.

OTHER TIPS

Make sure you've changed the Content Mode for your table in IB (Attributes Inspector). You want View Based, not Cell Based.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top