My steps using storyboard
- Create a Mac Cocoa app using storyboard. Drag a Table View from the right sidebar onto the storyboard.
- Let the pre-existing ViewController to follow
NSTableViewDataSource
protocol. Implement two methods inViewController.m
:numberOfRowsInTableView:
returns 10 andtableView:objectValueForTableColumn:row:
returns @"321". - 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
- Use .xib rather than .storyboard. Drag a Table View from the right sidebar onto the storyboard.
- Create a class MyTableViewController who follows
NSTableViewDataSource
protocol. Implement the same two methods. - In xib, drag a new object to the object. Change its class to MyTableViewController and connect the object to the table view's dataSource.