How should child views of UIScrollView report their bounds for contentSize?

Posted by Mike on Stack Overflow See other posts from Stack Overflow or by Mike
Published on 2010-05-23T21:05:30Z Indexed on 2010/05/23 21:11 UTC
Read the original article Hit count: 323

Filed under:
|
|

I'm looking more for advice on the correct design for a view.

What I have is a UIScrollView that contains one or more custom Views I have created. My problem is, who reports to the scrollview what it's contentSize should be? I have the following:

UIView  
+-UIScrollView  
  +-CustomView 1 with dynamic height depending on data
  +-CustomView 2 with dynamic Height depending on data

The UIViewController creates new instances of the custom views with data and then adds them as subviews to the UIScrollView. The problem I'm having is how to set the value of the scrollview's contentSize? Right now, I'm not doing that and the contents of the scrollview are clipped with no scrolling possible.

  • Should the custom view call [parent setContentSize:] in its drawRect:?
  • Should the UIViewController query the custom view after creation to get its bounds and then call setContentSize?
  • Should I subclass the UIScrollView to override addSubView to query each subview's height?
  • Is there something else I'm missing?

I hope I explained that properly. I'm new to this and still getting a handle on things.

© Stack Overflow or respective owner

Related posts about iphone-sdk

Related posts about uikit