iOS 5 ScrollView添加子视图导致EXC_BAD_ACCESS

时间:2012-07-31 15:48:24

标签: ios5 uiviewcontroller uiscrollview

ARC,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;

1 个答案:

答案 0 :(得分:0)

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

相关问题