2

Forgive me for this being a fairly vague question on NSScrollView classes. I am just not really understanding them, despite having read up on them a bunch.

I have a NSViewController subclass which has a xib. In this view I drop in an NSScrollView. I connect an IBOutlet from the view controller class.

This is where I get confused.

What is the difference between the NSScrollView documentView and clipView? When added inside the xib the scrollview is given an NSClipView. Why?

If I want to add a subview to my scrollview inside the xib, I can only drop a view into the NSClipView of the NSScrollView and not the scrollview directly. I also see, when I resize the NSClipView so that itself, clips a subview I dropped in, scroll bars appear on the scrollview. However, when I run my app, I can't scroll. Secondly, the subviews don't appear when the app is running anyway.

Would someone explain how an NSScrollView works? Everything I have read on it thus far hasn't made it click with me.

halfer
  • 19,824
  • 17
  • 99
  • 186
Josh Kahane
  • 16,765
  • 45
  • 140
  • 253

1 Answers1

2

The clip view and scroll view work together to provide the scrolling behaviour. The clip view does the actual clipping of the document view (which is the view you want to present in the scroll view).

The scroll/clip view largely know how to behave by querying the size of the document view, so it's important that you have configured your NSView-subclass to behave correctly in this way by (typically) calling [self setFrameSize:newSize] whenever the content changes. If you get this right then it should just work

In order to solve the actual issues you are facing, however, I would need to see some code, so if you can reproduce the problem within a simple self-contained Xcode project that I can look at, then that is the best way forward (however note I won't be able to look at it at the current time).

Droppy
  • 9,691
  • 1
  • 20
  • 27
  • Thanks! The problem I was having was I felt the need to place my subviews directly in the scrollview/clip view. I created a separate view with an `IBOutlet` and set that as the document view. Now it all works! Thanks for explaining. – Josh Kahane Aug 06 '14 at 11:11
  • @JoshKahane You're welcome. Actually you should have been able to plonk the view into the scrollview and got it to work using IB. – Droppy Aug 06 '14 at 12:27