Sunday, May 6, 2012

NSOutlineView Source List -- issues with auto layout

So in my app, I was experiencing a similar problem described by Chris Miller here. Essentially, using auto layout with NSOutlineView is causing two major alignment issues:

  1. The first problem has to do with the baseline of the text. Unselected, the baseline is higher than it should be. Upon selection, the baseline re-adjusts itself correctly. Chris has a neat video on this issue which is available from his article.
  2. The second problem has to do with the horizontal spacing between the disclosure triangle with the NSImageView. This problem was not described by Chris perhaps because I had my NSOutlineView configured as a source list.

Chris' solution to make the height of the row static did not work for me. What ended up working is:

  1. Add a constraint (called "Pin" in the Xcode menu) to make both the image view and the text field have a constant and equal height. This solves the first issue.
  2. After calling reload: on the view, call display in the next run loop. This solves the second issue. You may want to do this before calling expandItem: so that the view does not flicker when it adjusts the distance between the disclosure triangle and the image view.