0

I made a custom NSTableCellView. I created my own custom NIB file, which the root view class is assigned to my CustomTableCellView class.

The XIB file hierarchy is as follows: enter image description here

Then, during the awakeFromNib I register my custom NSTableCellView:

[_table registerNib:[[NSNib alloc] initWithNibNamed:@"CustomTableCellView" bundle:nil] forIdentifier:@"CustomCellView"];

And during -[NSTableView tableView:viewForTableColumn:row:] I return my custom cell view like this:

CustomTableCellView *cellView = (CustomTableCellView *)[_table makeViewWithIdentifier:@"CustomTableCellView" owner:self];

return cellView;

But once the table view is displayed, I don't see the cell view properly aligned. I always see the cell like this:

enter image description here

Where you can see in the top right corner that the buttons are there but misaligned.

What do I need to do to properly center the other cell view with the one that has the Test text?

Jacobo
  • 1,259
  • 2
  • 19
  • 43
  • Did you add constraints to the buttons and/or stack view? Should the height of the cell view be adjusted to the row height or the row height to the cell view? – Willeke Sep 28 '20 at 10:47
  • I didn’t add any constrain. Just to the stack view to have 10 pots as trailing and leading spaces. The cell view should adjust to the height of the row and be centred in the row. – Jacobo Sep 28 '20 at 11:05
  • 1
    Have you tried adding top and bottom constraints to keep the stack view inside the cell view? – Willeke Sep 28 '20 at 11:23
  • I can’t add constraints to the view that is enclosing the stack view. I tried to add some top and bottom constrains of 20 and the stackview stay the same – Jacobo Sep 28 '20 at 11:28
  • If the cell view doesn't fit inside the row then part of it will be invisible. – Willeke Sep 28 '20 at 12:02
  • Why it won’t fit? I had that stackview in a cell view on the XIB file of the table view, but I had to move it to be able to initialise all the buttons. Is there a way to set the size of the view before is displayed? – Jacobo Sep 28 '20 at 12:07
  • The cell view is automatically resized to fit the row height and column width. Was the height of the cell view in the table view the same as the cell view in the xib? – Willeke Sep 28 '20 at 13:27
  • @Willeke you are right, after adding constraints to the top and the bottom, I'm able to see my custom cell view in the table. Thanks! – Jacobo Sep 28 '20 at 17:44

0 Answers0