修改超类的属性

时间:2012-02-21 15:32:09

标签: iphone objective-c

我想让UIViewController视图类成为一个scrollView。我该怎么做?

2 个答案:

答案 0 :(得分:2)

只需在UIScrollView方法中将视图初始化为-loadView(您需要覆盖它)。

- (void)loadView {
  self.view = [[UIScrollView alloc] initWithFrame:...];
  // do other init stuff;
}

您无需致电[super loadView],它只会分配默认UIView个实例,并将其分配给view

答案 1 :(得分:1)

为什么不:

@implementation MyScrollViewController
...
...
-(void)viewDidLoad
{
    [super viewDidLoad];
    //configure my scrollview (self.view).  This may require you to cast your self.view to UIScrollView.
}
-(void)loadView
{
   UIScrollView *sv = [UIScrollView alloc] init] autorelease]; //will be retained by self.view
   self.view = sv ;
}
...
...
@end