Recently i've downloaded Xcode 4.5(iOS 6),but when tried to continue one of my projects i noticed that the UIScrollView isn't working properly,let me explain more clearly:
I've created the UIScrollView and added the initialized it using the following code:
-(void)viewDidLoad{
[mainScrollView setScrollEnabled:YES];
mainScrollView.contentSize = CGSizeMake(480, 0);
[super viewDidLoad];
}
After i opened my XIB and linked the mainScrollView
to a UIScrollView,after i added some UIButton's to the scrollView.When i built the project the mainScrollView
was scrolling but the buttons didn't showed up,i mean,i just could see the button that were already on the screen.What i'm doing wrong?How can i setup the UIScrollView?
I would do it like this:
I use the class variable _y since I add all the subviews heights to it.
For
xcode 4.5
,If you are usingscrollView
you have to either uncheck "use AutoLayout
" in file inspector.or if you want to "use
AutoLayout
",then in .m(implementation) file add thisMaybe you just typed this wrong, but your
CGSize
has a height of 0?If you would like to fix this AND use AutoLayout, move your
contentSize
code to theviewDidAppear
method. I found the answer in this SO question: Embed ImageView in ScrollView with Auto Layout on iOS 6You can do it with Auto Layout in XCode 4.5 But you config your UIScrollView in viewDidAppear
I do this also in a static UITableView with images.
Name your images like timg1.png, timg2.png....
in your ControllerView.h File
In your ControllerView.m File
I believe this is a bug with either Xcode 4.5 or the iOS 6 SDK. The way I fixed it was by adding the subviews to my UIScrollView programatically.
So you would have to do something like:
Try this and let me know if this worked for you.
If you have an old version of Xcode it might be a good idea to replicate the code and the nib over there to see the results.