Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSTableView only displaying "Table View Cell"

I have a NSTableView with the delegate and datasource pointing to my controller. I have tried implementing the

- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex

Method, but no matter what I return, the table always shows "Table View Cell" in the data. Any ideas of what I could be doing wrong? Attached are two pics showing that I have the delegates set properly (it also shows the proper number of rows).

What the table showsenter image description here

Note that I have also just tried returning @"Hello World" for everything, but I get the same result.

like image 878
Kyle Avatar asked Sep 23 '11 19:09

Kyle


4 Answers

Just change the Content Mode to Cell Based for the table view in IB. IB will display Text Cell as the cell placeholders, which are populated at runtime by whatever you return from tableView:objectValueForTableColumn:row:

like image 55
JAWZapps Avatar answered Oct 27 '22 01:10

JAWZapps


Finally figured it out. My cells for some reason seem to contain both a TableCellView AND a text field cell. I removed the Table Cell View's and now everything is working. I have no idea how I got in that state.

enter image description here

like image 11
Kyle Avatar answered Oct 27 '22 03:10

Kyle


Newer version of XCode:

  1. Select the table view (make sure the scroll view or any other view is not selected).
  2. On the right hand side, select the "Attribute Inspector"
  3. Change the Content Mode to "Cell Based" instead of "View Based"
  4. Save your changes and re-run the project.
like image 9
Gaurav Avatar answered Oct 27 '22 03:10

Gaurav


Most of the responses involve converting the table view component to a cell-based table view. If that’s what you want then that’s fine, you’re good to go. At the time the question was asked, cell-based tables were the norm and when Apple changed the window component to a view-based one it obviously caused a lot of confusion. Today, Apple’s docs recommend that you should use view-based rather than cell-based tables.

The problem described in the question arises if you use - tableView:objectValueForTableColumn:row: in your datasource. You cannot use this method with view-based tables, it is only for cell-based tables. Instead you need to use the NSTableViewDelegate method - tableView:viewForTableColumn:row:. You don't need to make the object conform to the NSTableViewDelegate protocol to use this method but it must be set as the delegate of the table.

In response to Cœur, quoting from the Apple On-line docs.

NSCell-Based Tables Are Still Supported In OS X v10.6 and earlier, each table view cell was required to be a subclass of NSCell. This approach caused limitations when designing complex custom cells, often requiring you to write your own NSCell subclasses. Providing animation, such as progress views, was also extremely difficult. In this document these types of table views are referred to as NSCell-based table views. NSCell-based tables continue to be supported in OS X v10.7 and later, but they’re typically used only to support legacy code. In general, you should use NSView-based tables.

like image 9
psmythirl Avatar answered Oct 27 '22 01:10

psmythirl