0
votes

My steps using storyboard

  1. Create a Mac Cocoa app using storyboard. Drag a Table View from the right sidebar onto the storyboard.
  2. Let the pre-existing ViewController to follow NSTableViewDataSource protocol. Implement two methods in ViewController.m: numberOfRowsInTableView: returns 10 and tableView:objectValueForTableColumn:row: returns @"321".
  3. In storyboard, connect the Table View's delegate and dataSource to (the only) View Controller.

The Problem

Every cell displays "Table View Cell" rather than the data I want to fill. In spite of that, tableView:objectValueForTableColumn:row: was indeed called 10 times.

The alternative using .xib

https://www.youtube.com/watch?v=p5U94-uRCOo

  1. Use .xib rather than .storyboard. Drag a Table View from the right sidebar onto the storyboard.
  2. Create a class MyTableViewController who follows NSTableViewDataSource protocol. Implement the same two methods.
  3. In xib, drag a new object to the object. Change its class to MyTableViewController and connect the object to the table view's dataSource.
1

1 Answers

0
votes

Your table view needs to be cell based not view based. Loot at the documentation.

tableView:objectValueForTableColumn:row: is for cell based tables and

- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row is for view based table views.