0

弧,iOS 5,XCode 4.2

我正在尝试使用页面控件(类似于主屏幕)实现分页滚动视图,但我似乎无法让它工作。相关代码为:

- (void)viewDidLoad
{
    [super viewDidLoad];

    [scroll setDelegate:self];
    [scroll setContentSize:CGSizeMake(2 * [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height)];
    [scroll setPagingEnabled:YES];

    pageControl.currentPage = 0;
    pageControl.numberOfPages = 2;

    UIView* view = [[self.storyboard instantiateViewControllerWithIdentifier:@"VALID_ID_1"] view];
    view.frame = CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height);

    [scroll addSubview:view];

    UIView *aView = [[self.storyboard instantiateViewControllerWithIdentifier:@"VALID_ID_2"] view];
    aView.frame = CGRectMake([[UIScreen mainScreen] bounds].size.width, 0, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height);

    [scroll addSubview:aView];
}

调用该instantiateViewControllerWithIdentifier方法会返回一个结果。

我尝试过的事情:

  • 在此特定文件上禁用 ARC
  • alloc] init]在视图控制器上使用

编辑:我可能应该显示声明:

//MyViewController.h
@property (strong, nonatomic) IBOutlet UIScrollView* scroll;

...

//MyViewController.m
@synthesize scroll;
4

1 回答 1

0

最有可能的scrollnil。请检查..!

于 2012-07-31T16:04:57.767 回答