0

I have a NSTableView with 3 cells. I have adjusted that table view to show the separators, by using this code:

  [self.tableView setGridColor:[NSColor lightGrayColor]];
  [self.tableView setIntercellSpacing:NSMakeSize(1, 1)];
  [self.tableView setGridStyleMask:NSTableViewDashedHorizontalGridLineMask];

When I render the table I see this:

enter image description here

The table shows a number of cells that are not supposed to exist and with a different size!

Is this normal? How do I get rid of those "phantom cells"?

UFO
  • 219
  • 3
  • 8

2 Answers2

1

You cannot remove those "phantom" cells. That's just the way the table view works

If this is not acceptable take a look at NSStackView or NSCollectionView as ways of vertically stacking your cells (which will have to be created as custom views). They are more flexibly in terms of presentation.

Daniel Farrell
  • 9,316
  • 8
  • 39
  • 62
  • wow, that is horrible. UITableViews work correcly on iOS and indeed NSTableViews look correctly on storyboard. Man, UI elements on Cocoa are very poor compared to iOS. Thanks for the answer. – UFO Jan 01 '15 at 17:20
  • I think it's a bit harsh to suggest that OS-X lags far behind iOS in terms of the UI elements it offers. They have different strengths and weaknesses of course, but once you're used to the API's I think you'll find as much scope for customization on the Desktop as you do on the mobile platform. I flit between the two, but much prefer the former - if only because it allows me to harness the magic of *Bindings*. – Paul Patterson Jan 01 '15 at 21:23
  • Bindings are good, but iOS APIs are far more powerful regarding to UI in relation to the equivalent Cocoa's. Not to mention the disgrace that is Interface Builder for Cocoa, lacking a lot of properties that the iOS version has for the equivalent classes. Even considering that they are different platforms, Apple has to unify as much as possible the APIs. It is inadmissible two methods on equivalents APIS to do the same thing that are spelled different, like setString and setStringValue or setAlpha and setAlphaValue. There is no reason for that to exist. Just create difficulties. – UFO Jan 02 '15 at 10:43
1

If all the content rows in your table are the same size, you can use the NSTableView size inspector to specify the size. If you do this, the system-added 'padding' rows will have this size also.

enter image description here

To get rid of the grid lines associated with the system-added rows, the snippet below worked for me in a very quick demo app (this snippet is not my own, it was taken from an answer to another Stackoverflow question)

// MyNSTableView.m (only need to override this one NSTableView method)

- (void)drawGridInClipRect:(NSRect)clipRect
{
    NSRect lastRowRect = [self rectOfRow:[self numberOfRows]-1];
    NSRect myClipRect = NSMakeRect(0, 0, lastRowRect.size.width, NSMaxY(lastRowRect));
    NSRect finalClipRect = NSIntersectionRect(clipRect, myClipRect);
    [super drawGridInClipRect:finalClipRect];
}

Combining the two gives the following effect (I'm using alternating row colors to show that the gird lines are indeed not drawn for the system-added padding rows).

enter image description here

Community
  • 1
  • 1
Paul Patterson
  • 6,840
  • 3
  • 42
  • 56