Search code examples
objective-ccocoanstableviewnsarraycontroller

NSTableView Layout issue with Highlight and Background Color


I am basically trying to recreate the popOver that exists in certain Xcode Settings, like this one in Build Settings:

enter image description here

I have tried both with and without using an NSArrayController to control the content but in each of the tests I ran in to different problems I haven't been able to solve.

Desired Result

  • Complete White Background
  • Multiple Selection and (Single) Editable Cells
  • No Reordering is required
  • When I press the + button I want the new cell to be selected and in edit mode
  • I want to get notification of when text changes while editing to be able to respond to that.

1. Using Delegate Methods.

When I had set up everything up I got this result:

enter image description here

That didn't look good, so I went and selected "Draws Background" for the NSTableViewCell, which resulted in this which looks nice when I edit a cell:

enter image description here enter image description here

But when i just Highlight the cell, it looks like this:

enter image description here

It looks like the highlighting get's placed behind the cell background.

Here I'm stuck and don't know how to fix.

2. Using NSArrayController

When I reconfigure and bind this to an NSArrayController the highlighting looks great:

enter image description here

But when I edit a cell, the entire background changes to grey:

enter image description here

This is also not what I want, but can't figure out what to do about.

--

Notes

In Desired Result I listed some things like "When I press the + button I want the new cell to be selected and in edit mode" and "I want to get notification of when text changes while editing to be able to respond to that." To possibly influence the choice of what route to take, as there are more things about thins TableView I haven't figured out.

But this question Is all about how to fix the highlighting and selection so they stay white all the time, and just selecting a cell looks as expected.

Example Code

Example code for the Delegates Method version:

https://github.com/erikberglund/StackOverflow/tree/master/TableViewDelegates

Example code for the Bindings version:

https://github.com/erikberglund/StackOverflow/tree/master/TableViewBindings


Solution

  • Force the appearance to aqua. So instead of inherited select aqua. This solved the issues for me.

    Aqua