Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

larswik

macrumors 68000
Original poster
Sep 8, 2006
1,552
11
It looks like Apple changed something and I can't figure it out. I looked at some old osx apps that work but a new project I am working on isn't.

Simple set up so far, TableView with 2 columns and when I press an NSButton it should fill the tableview with "102" in the ID column and "Pet Lounge..."

Included 4 photos to better illustrate what I see. The screen shot at 4:03 shows that I labeled the the text cells and also the identifier to the right under the identity inspector.

2 of the photos show the identifier is "idNum" and the other show the Client object has a value for idNum that is "102" which should be returned.

The last image is of the app after I pressed the button 3 times, it just says "Text View Cell" 3 times. I'm pretty sure I am missing something simple here and something has changed with the NSTableViews from previous versions. I did search for tutorials but everything I followed was old, nothing from xcode 6. Anyone have an idea of the step that I am missing?

Code:
#import "TableViewController.h"

@implementation TableViewController

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

-(void)awakeFromNib{
    tableView.delegate = self;
    tableView.dataSource = self;
}

-(IBAction)addButton:(id)sender{

    [list addObject:[[Client alloc]init]];
    [tableView reloadData];
}

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

-(id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row{
    Client *c = [list objectAtIndex:row];
    NSString *identifier = [tableColumn identifier];
    
    return [c valueForKey:identifier];
    

}
 

Attachments

  • client.jpg
    client.jpg
    90.6 KB · Views: 131
  • idNum.jpg
    idNum.jpg
    56.5 KB · Views: 113
  • Screen Shot 2015-01-26 at 4.03.02 PM.png
    Screen Shot 2015-01-26 at 4.03.02 PM.png
    122.5 KB · Views: 139
  • Screen Shot 2015-01-26 at 4.20.02 PM.png
    Screen Shot 2015-01-26 at 4.20.02 PM.png
    21 KB · Views: 242

Ritsuka

Cancelled
Sep 3, 2006
1,464
968
Lion introduced view-based tableviews that works in a different way. If your tableview is view-based you to implement the

Code:
- (NSView *)tableView:(NSTableView *)tableView
   viewForTableColumn:(NSTableColumn *)tableColumn
                  row:(NSInteger)row;

data source method.

You can switch between cell-based and view-based tableviews in the xib. If you don't need 10.6 compatibility you should use the view-based one.
 
Last edited by a moderator:

larswik

macrumors 68000
Original poster
Sep 8, 2006
1,552
11
Thanks for the reply, I will check it out today. I do need 10.6 since that is the os that it will need to run on at work.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.