1

Should be an easy question, but there's nothing in the interface. Apart from seeing whether something like preparedCellAtColumn:row: throws an exception, is there anything else one can do?

Except that preparedCellAtColumn:row: doesn't throw an exception, it just logs a message, and returns an NSCell object, so you can't test it for nil.

Cœur
  • 37,241
  • 25
  • 195
  • 267
AlexT
  • 596
  • 7
  • 15
  • why does it matter? If Apple doesn't offer a simple -isViewBased property, they might have a reason for that. – Volker Apr 14 '14 at 07:14
  • 1
    Check out the (very) complete answer on this question http://stackoverflow.com/questions/19218807/how-does-the-nstableview-set-content-modeview-based-or-cell-based-by-code – cacau Apr 14 '14 at 07:28
  • Well, I have (had) a useful routine that gathered all the text in the table into an array of tab-delimited strings, that could then be placed on the pasteboard and pasted as text into other applications. How you get the text from each cell very much depends on whether it's cell-based or not. I know at design time of course, but I'd prefer to keep my code as general as possible, and not have to rewrite as I gradually update to view-based tables. – AlexT Apr 18 '14 at 12:19
  • That's well-worth with reading. But my tables tend to be populated from core data via an array controller, all set up by bindings in the xib file, so I don't need any delegate or datasource methods. – AlexT Apr 18 '14 at 12:30

2 Answers2

0

Funny that several people say that there’s no need to know when the questioner obviously does have that need. And there are good reasons you might want to know this; e.g. if you implement a generic NSTableView subclass or delegate, you must differentiate its behavior dependent on whether the table view is view- or cell-based.

If you use an NSArrayController and bindings, an easy way is to check for NSTableColumn bindings, because cell-based NSTableViews do have these, and view-based NSTableViews do not. So this code fragment will work:

        NSTableColumn *tableColumn = [[myTableView tableColumns] objectAtIndex:0];
        NSDictionary *binding = [tableColumn infoForBinding:@"value"];
        if (binding) {...}  // cell-based table view
        else {...}  // view-based table view

I haven’t tried myself, but if you use an NSTableViewDataSource instead, you’d probably simply check whether the data source responds to - tableView:setObjectValue:forTableColumn:row: (cell-based table view) or not (view-based table view).

Uli Zappe
  • 306
  • 3
  • 8
-2

There is no need to tell it, if you use objectValueForTableColumn it will automatically become cell based and on the other side if you use viewForTableColumn then it will be view based. You can pass any type of view in both of these methods.

Qasim Ali Khan
  • 492
  • 4
  • 11