UIScrollView with stationary view above it

Discussion in 'iOS Programming' started by Kizmar, Nov 9, 2010.

  1. Kizmar, Nov 9, 2010
    Last edited: Nov 9, 2010

    Kizmar macrumors newbie

    Kizmar

    Joined:
    Oct 28, 2010
    #1
    So I have a view controller with a UIScrollView on it working just fine. I'd like to put a view above it with some buttons on it that stay there when you scroll down. When I do so, however, it's not rendering anything that's not in the scrollView.

    Here's an example of my View Controller hierarchy:
    • View
      • Position 1
      • Scroll View
        • View
          • ...bunch of stuff here...
        • View
          • ...bunch of stuff here...
      • Position 2

    I've tried putting the "stationary" view in both "Position 1" and "Position 2", but it's just not showing.

    I've also tried setting the Scroll View's Content and Scroller Inset top values to 40 to make sure there was room for the stationary view to show above the scroll view... still no luck.

    Am I missing something, doing something wrong... or is this not possible because the scroll view is taking control of the entire view controller area?

    Thanks

    [Edit] As I was writing this I decided I should try this with the scrollView inside and at the end of the view I want stationary... still doesn't appear to show the buttons.
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    How are you adding the views? Some code might help. It's hard to debug descriptions.
     
  3. Kizmar, Nov 10, 2010
    Last edited: Nov 10, 2010

    Kizmar thread starter macrumors newbie

    Kizmar

    Joined:
    Oct 28, 2010
    #3
    Everything on this view controller was added with the Interface Builder. There are no dynamic views added at load.

    The only lines of code I added that are relevant to this issue:
    Code:
    - (void)viewDidLoad {
    	...
    	
    	// make this scrollable
    	UIScrollView *scrollView = (UIScrollView *)self.view;
    	scrollView.contentSize = CGSizeMake(320, 700);
    	
    	...
    }
    
    I might be better served asking the question more generically:

    If I wanted to use a scrollview yet still have a view at the top not scroll, what's the proper way to do this?

    I'm trying to avoid using the scrollViewDidScroll method to move the view that should stay at the top. Seems like there should be a more conventional way.

    I have Googled my fingers off and I'm not finding what I'm looking for. ;)
     
  4. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    Maybe some screenshots of your IB setup will help us to see what you have. Show us not just the layout of the screen but also the window titled ViewName.xib.

    Add the two views as subviews of their container. That is, they should be siblings of each other in the view hierarchy and not super/sub, by which I mean the stationary view should not be a subview of the scroll view.
     
  5. Kizmar thread starter macrumors newbie

    Kizmar

    Joined:
    Oct 28, 2010
  6. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #6
    Hmm, your IB setup looks fine, as far as I can tell.

    But now that I look at your code again, I'm concerned about this line:
    Code:
    UIScrollView *scrollView = (UIScrollView *)self.view;
    Are you sure self.view is the scroll view at this point and not the overall view?
     
  7. Kizmar, Nov 10, 2010
    Last edited by a moderator: Nov 10, 2010

    Kizmar thread starter macrumors newbie

    Kizmar

    Joined:
    Oct 28, 2010
    #7
    Yer right, at this point it's going to be a subview of self.view. I changed it around so much while I was troubleshooting that got left in the dust.

    So that brings me to another question; what outlets should the scrollview have? Currently it has one outlet "view -> File's Owner". I ended up with that reference outlet after troubleshooting why it wasn't scrolling.

    Could this be messing with it's sibling subview?

    Should this be set up as an IBOutlet property the same way I access the labels?

    EDIT:
    Hah... that was it!

    I created an outlet property for the scrollView and referenced that instead of view, then set self.view's reference to "view".

    Leftover troubleshooting changes that didn't get cleaned up by the time I had half a clue what I was doing.

    It works now. Thanks for a point in the right direction! :D
     

Share This Page