سؤال

The scroll view shows up, without any of the views visible. The view moves fine, the page control works. When i change the scroller background that all works fine. The views "the different colours" don't show. Have no idea whats wrong. Thanks for the help

-(void)viewDidLoad {    
[super viewDidLoad];

CGRect frame = CGRectMake(0, 215, WIDTH_OF_IPHONE, HEIGHT_OF_SCROLLER);

int numOfPhotos = 6;

scrollViewer = [[UIScrollView alloc] initWithFrame:frame];
scrollViewer.contentSize = CGSizeMake((WIDTH_OF_IPHONE*numOfPhotos), HEIGHT_OF_SCROLLER);
scrollViewer.pagingEnabled = YES;
//scrollViewer.backgroundColor = [UIColor lightGrayColor];
[scrollViewer setDelegate:self];

int i = 0;

while (i < numOfPhotos){

    CGRect frameOfView = CGRectMake((i*320), 215, 320, HEIGHT_OF_SCROLLER);
    UIView *photoFrame = [[UIView alloc] initWithFrame:frameOfView];

    if (i == 0){
        photoFrame.backgroundColor = [UIColor redColor];//colorWithPatternImage:image1];
        NSLog(@"colour was selected");
    }else if (i==1){
        photoFrame.backgroundColor = [UIColor blueColor];//colorWithPatternImage:image2];
    }else if (i==2){
        photoFrame.backgroundColor = [UIColor purpleColor];//colorWithPatternImage:image3];
    }else if (i==3){
        photoFrame.backgroundColor = [UIColor orangeColor];//colorWithPatternImage:image4];
    }else if (i==4){
        photoFrame.backgroundColor = [UIColor magentaColor];//colorWithPatternImage:image5];
    }else{
        photoFrame.backgroundColor = [UIColor greenColor];//colorWithPatternImage:image6];
    }

    [scrollViewer addSubview:photoFrame];
    //[photoFrame release];

    photoFrame = NULL;
    i++;
}
pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(0, 0, WIDTH_OF_IPHONE, 15)];
pageControl.center = CGPointMake(scrollViewer.center.x, (208+HEIGHT_OF_SCROLLER));

[pageControl setNumberOfPages:numOfPhotos];

[pageControl addTarget:self action:@selector(pageSwiped:) forControlEvents:UIControlEventValueChanged];

[self.view addSubview:scrollViewer];
[self.view addSubview:pageControl];

My .H file looks like this

@interface HomePage : UIViewController <UIActionSheetDelegate, UIScrollViewDelegate> {

   IBOutlet UIScrollView *scrollViewer;
   UIPageControl *pageControl;
   BOOL pageControlUsed;

}
@end
هل كانت مفيدة؟

المحلول

Try setting the y origin of the photoFrame to 0 as it will place it under the actual frame of your scrollview.

If not the problem you are having is that you are making the photoFrame NULL. If you are using ARC you shouldn't worry as the Garbage Collector will take care of it.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top