Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Kizmar

macrumors newbie
Original poster
Oct 28, 2010
22
0
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.
 
Last edited:
How are you adding the views? Some code might help. It's hard to debug descriptions.

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. ;)
 
Last edited:
Everything on this view controller was added with the Interface Builder.
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.

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?
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.
 
This what you mean?
 

Attachments

  • Screen shot 2010-11-10 at 12.06.35 PM.png
    Screen shot 2010-11-10 at 12.06.35 PM.png
    374.9 KB · Views: 153
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?
 
Are you sure self.view is the scroll view at this point and not the overall view?

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
 
Last edited by a moderator:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.