UIView setBounds UIScrollView hell?

You want to layout your subviews by setting their frame .

Up vote 0 down vote favorite share g+ share fb share tw.

I have a bunch of 'rowviews' that I want to put in a vertical scroll view. I have created this rowView view as a separate nib in IB. They are sized at 1024/200 (ipad).

Now I want to put them one by one in my parent UIScrollView. I tried a simple vScroll addSubview:rowView but this puts them overtop of eachother (I made the rowview transparent to check this). So then I started fooling with the bounds of each rowview to no avail.

This is my code. Note 'self. YExtentSoFar' is initialised to 0.

Imagine the code below called for each row: MyRowView *rowView = MyRowView alloc init; float calculatedWidth = 0; // minus nav bar float calculatedHeight = 0; UIDevice currentDevice beginGeneratingDeviceOrientationNotifications; UIInterfaceOrientation orientation = UIDevice currentDevice. Orientation; if (orientation == UIInterfaceOrientationPortrait){ // iPad calculatedWidth = 768.0; calculatedHeight = 960.0; }else{ // iPad calculatedWidth = 1024.0; calculatedHeight = 704.0; } self. VScroll addSubview: rowView.

View; rowView. View setBounds:CGRectMake(0, self. YExtentSoFar, calculatedWidth,200); self.

VScroll setContentSize:CGSizeMake(calculatedWidth, yExtentSoFar+200); self. YExtentSoFar += 200; So before I tried settings bounds the rowviews appeared overtop of each other. Understandable I guess.

When I set the bounds, the 2nd row view hasn't appeared under the 1st as expected, instead I have to pull down the vScroll and the 2nd has appeared ABOVE the first off screen! Could someone point to where I'm going wrong? Thanks a lot, Mike iphone objective-c uiview uiscrollview link|improve this question edited Jun 30 '10 at 4:38ohhorob3,17921128 asked Jun 29 '10 at 23:48Mike Simmons5941320 92% accept rate.

– Mike Simmons Jun 30 '10 at 0:08 on the iPhone for views, yes. – Dave DeLong Jun 30 '10 at 0:26 Ok, well then why would a y value of 200 put it in negative? – Mike Simmons Jun 30 '10 at 0:37.

You want to layout your subviews by setting their frame. Specifically you're confusing the reference co-ordinates.. bounds refers to how much of that view to show. Whereas the frame is where (& what size) should the view be placed in it's superview.

See "The Relationship of the Frame, Bounds, and Center" View Programming Guide for iPhone.

Perfect! Thankyou :) – Mike Simmons Jun 30 '10 at 5:33 Also, when working with a collection of views in a UIScrollView, I keep them in a container view. This helps when I need to iterate over the "scrolled" subviews to do work with them.

If you rely on myScrollView. Subviews you will get the scroll bar indicator views included! (the container view is my only subview of myScrollView) – ohhorob Jun 30 '10 at 5:44.

You're doing it wrong ;-) What you have explained here is more or less a re-implementation of what you get using a UITableView. Use a UITableView and a custom table view cell. It will make your life much easier.

Using a custom UITableCell view sounds more complex. I just want to chuck my views in a UIScrollView. Why are they appearing on top of each other (off the screen) instead of below each other.

I can't imagine whenever a vertical scroll situation is needed people use a UITable. – Mike Simmons Jun 30 '10 at 2:36 Not to be snarky, but actually, whether you can imagine it or not, people do use UITableViews very often. According to your description in your question it's exactly what you need.

Learn how to use table views. As I said before, it will make your life much easier. Trust me.

;-) – Matt Long Jun 30 '10 at 3:27 First of all thankyou for your answer. I just feel that re-using an existing component is only useful if you are getting functionality for free you would otherwise have to create. Once I implement all the delegate methods and stuff for tables and fool around with custom table cell views I could have written the 3 lines for a vScrollView.

I also just wanted to know out of interest what was going wrong with my thing. @ohhorob answered that for me. Thankyou for your answer though!

I'll give them a try next time. – Mike Simmons Jun 30 '10 at 5:33.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions