UIScrollView中具有多个笔尖的未声明视图

时间:2011-07-18 08:08:46

标签: iphone xcode uiscrollview addsubview

我正在尝试使用3个笔尖在同一个UIScrollView中渲染3个不同的视图。但是xcode不断回馈视图未声明的错误

- (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];
}

在这个例子中,Xcode会说MainWindow,view2和view 3都是未声明的。我做错了什么?

1 个答案:

答案 0 :(得分:1)

通过

声明一个对象
NSObject *object

您可能希望

UIView *view2 = ...

声明并定义view2