Pregunta

I'm try to add a scrollview totally by code to a modal view, but it doesn't show. I've tried different ways but I can't see the mistake, Somebody could help me?

here my code:

@interface AddWithScrollOrizontal ()<UIScrollViewDelegate>{

    //IBOutlet UIScrollView*scroll;

}
@property (strong, nonatomic) UIScrollView*scroll;

@implementation AddWithScrollOrizontal

@synthesize scroll;

- (void)viewDidLoad
{

 self.scroll = [[UIScrollView alloc]init];

self.scroll.delegate = self;

    if (IS_IPHONE_5) {
        self.scroll.frame = CGRectMake(0, 58, 320, 270);
    }else{
        self.scroll.frame = CGRectMake(0, 20, 320, 270);
    }

    self.scroll.backgroundColor = [UIColor redColor];
    self.scroll.pagingEnabled = YES;
    self.scroll.contentSize =CGSizeMake(1280, 270);


UIView*firstView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 270)];
...
UIView*fourthView = [[UIView alloc]initWithFrame:CGRectMake(960, 0, 320, 270)];

    [self.scroll addSubview:firstView];
    [self.scroll addSubview:secondView];
    [self.scroll addSubview:thirdView];
    [self.scroll addSubview:fourthView];
    [self.view addSubview:self.scroll];
}
¿Fue útil?

Solución

You say you're adding it totally by code, but you're making an IBOutlet to scroll. Did you create it in IB? If not, your problem is that you never instantiate the scroll view. Also, there's no need to create an ivar for scroll, just create the property inside the @interface declaration for your class extension, and refer to it with self.scroll.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top