Reputation: 919
I'm trying to implement an UIScrollView with Page Control with an array of images. I used same piece of code of another project, but it doesn't work with Xcode 4.5. ScrollView frame properties are all 0 while debugging, but the scrollview Outlet is well connected. Images doesn't show in the scroll. It is really strange. I have observed that properties are not synthesized automatically like previous versions. Here is the code:
@interface dashboardViewController : UIViewController <UIScrollViewDelegate>{
BOOL pageControlBeingUsed;
}
@property (strong, nonatomic) IBOutlet UIScrollView *scrollView;
@property (strong, nonatomic) IBOutlet UIPageControl *pageControl;
- (IBAction)changePage;
@end
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageWithContentsOfFile:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"fondo.jpg"]]];
pageControlBeingUsed=NO;
scrollView.delegate=self;
[self buildScrollView];
// Do any additional setup after loading the view.
}
-(void)buildScrollView{
NSArray *imagesQueue = [[NSArray alloc] initWithObjects:[UIImage imageNamed:@"icoblog.png"], [UIImage imageNamed:@"icogaleria.png"], [UIImage imageNamed:@"icobio.png"], nil];
for(int i = 0; i < imagesQueue.count; ++i) {
UIImageView *image = [[UIImageView alloc] initWithImage:[imagesQueue objectAtIndex:i]];
CGFloat xOrigin = i * (scrollView.frame.size.width);
image.frame = CGRectMake(xOrigin, 0, scrollView.frame.size.width, scrollView.frame.size.height);
[scrollView addSubview:image];
image=nil;
}
scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width * imagesQueue.count, self.scrollView.frame.size.height);
}
Many thanks for your help.
Upvotes: 3
Views: 1969
Reputation: 881
Select your scrollview in the storyboard and untick the "auto layout" under file properties
Upvotes: 8
Reputation: 1807
Try pushing "self." infront of all the "scrollView" you don't have it.
Upvotes: 1