3

What is the main difference between cell based and view based tableviews in Cocoa.

The understanding I have is cell based tableviews are basically used for displaying strings and view based are for custom cells.User events such as dragging rows, selection etc can be handled in view based.

cell based tableviews use objectValueForTableColumn: method and view based tables use viewForTableColumn: method.

Is my understanding correct?. Or is any other design concerns between these table views. When to go for cell based and when to go for view based.

Thanks in advance

Daniyar
  • 2,975
  • 2
  • 26
  • 39
Chandan
  • 394
  • 6
  • 16

2 Answers2

6

short answer:

A cell can contain only one UI element like a text cell, image view cell, button cell and a few more. The customization ability is quite poor.

A view can contain multiple UI elements as well as other views. The customization ability is almost infinite.

Apple recommends to use always view based table views

vadian
  • 274,689
  • 30
  • 353
  • 361
  • Effective Explanation!!!. One more question. NSTableCellView is used for displaying image and text field per cell in tableview. So is that class used for view based tables? – Chandan Jul 09 '15 at 16:51
  • Indeed, there is a basic class with a single NSTextView and one with an NSTextView and an NSImageView. Subclassing to add custom elements is highly recommended. – vadian Jul 09 '15 at 16:56
4

NSCell is a lighter weight object and was a solution when it was a concern to have too many NSView objects. Think more than a decade ago. Cells are deprecated. Use views.

uchuugaka
  • 12,679
  • 6
  • 37
  • 55
  • 3
    NSCell is also a brilliant idea performance-wise, on how to only have a single object in memory per item-type, and thus be able to scroll through millions of lines, for the same (minimal) cost of dozen lines. An NSCell is like a visual template that has no data of its own, and no position. The NSTableView will (in a loop) move the cell, update its pointer to the correct data, and tell it to just draw itself. That's the magic. – Motti Shneor Nov 11 '17 at 19:30