Search code examples
iphonexcodeuiscrollviewaddsubview

Undeclared views in UIScrollView with multiple nibs


I'm trying to render 3 different views in the same UIScrollView using 3 nibs. But xcode keeps giving back the error that the views are undeclared

- (void)loadView {
    [super loadView];
    UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    scroll.pagingEnabled = YES;
    NSInteger numberOfViews = 3;


    MainWindow.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
    [scroll addSubview:MainWindow.view];
    view2.view.frame = CGRectMake(self.view.frame.size.width, 0, self.view.frame.size.width, self.view.frame.size.height);
    [scroll addSubview:view2.view];
    view3.view.frame = CGRectMake(self.view.frame.size.width*2, 0, self.view.frame.size.width, self.view.frame.size.height);
    [scroll addSubview:view3.view];

    scroll.contentSize = CGSizeMake(self.view.frame.size.width * numberOfViews, self.view.frame.size.height);
    [self.view addSubview:scroll];
    [scroll release];
}

In this example Xcode would say MainWindow, view2 and view 3 are undeclared. What am I doing wrong?


Solution

  • Declare an object by

    NSObject *object
    

    Do you may wish to do

    UIView *view2 = ...
    

    to declare and define view2