NSTableView Disappearing Text

I have a Mac Core Data application (not document-based) for journal writing using Xcode 7.1 on OS X 10.11. The main window is a split view. On the left side is a table view containing a list of dates. Selecting a date shows that date's journal contents in a text view on the right side of the split view. I use an array controller and Cocoa bindings to connect everything. The array controller is set to automatically prepare its content.

Everything works great when I launch the application. The table view shows the dates. Selecting a date shows its journal contents. But there are various things that will cause the text in the table view to disappear. Dragging the split view's divider causes the text in all the table view entries to disappear. Clicking in the text view causes the selected table view item's text to disappear. Selecting a table view item causes the previously selected item's text to disappear.

I can get the text in the table view to appear again by calling the table view's reloadData() method. But I'd prefer not to litter my code with calls to reloadData() in multiple places. I have a small example of a similar document-based Core Data application that uses bindings, and the text in the table view doesn't disappear, and I don't have to call reloadData(). I found no difference in how I set up the bindings in both projects.


What can I do to keep the table view text from disappearing? If there's no way to keep the text from disappearing, where do I call the table view's reloadData() method so the text appears to always be visible from the user's perspective?

The disappearing table view text is caused by the table view having Source List highlighting. Changing the table view's highlighting to Regular keeps the table view text from disappearing.


Why would the table view text disappear with Source List highlighting and not with Regular highlighting? The table view text is black and the Source List highlighting's background color is light gray.

Is the table view view-based or NSCell-based?


If the table is view-based, are you using auto layout? Did you set up constraints for the views in the hierarchy within the table cell views? Did you do that in Interface Builder or in code? What are the constraints? If you set up the constraints in code, show the code.


Are your cell views instances of (a subclass of) NSTableCellView? Did you connect its textField outlet to your text field (or leave it connected if it was by default)? Is the text field an immediate subview of the cell view or is the hierarchy more complex than that? Source List highlighting does weird things to the layout of the text field in -viewWillDraw:. If you text field isn't where it thinks it is, this can maybe explain the issue.


Did you implement -tableView:viewForTableColumn:row: or -tableView:didAddRowView:forRow:? If so, show that code.


Some more things to check: http://prod.lists.apple.com/archives/cocoa-dev/2015/Nov/msg00168.html, http://stackoverflow.com/a/21059755/1312143

The table is view-based. I'm using auto layout. I have the following constraints for the table view cells set up in Interface Builder:


Table View Cell.Center Y = Superview.Center Y
Superview.Trailing = Table View Cell.Trailing (Constant: -3)
Table View Cell.Leading = Superview.Leading (Constant: 14)


My table cell view is an instance of NSTableCellView. Its textField outlet is connected to my text field. The text field is an immediate subview of the cell view.


I didn't implement -tableView:viewForTableColumn:row: or -tableView:didAddRowView:forRow:.

Hmm. All of that seems non-problematic. You may need to use Xcode's view debugger to find if the view is hidden, zero-sized, outside of the bounds of its superview and thus clipped, or what. You can inspect the constraints to see what has caused the condition.

Thanks for the tip on using the view debugger. For now I'm going to stick with the regular highlighting because it works. I was curious why source list highlighting would make table view text disappear.

NSTableView Disappearing Text
 
 
Q