message sent to deallocated instance 错误
2015-10-23 来自:Sunnyday 0 人回应

在stroyboard下的scrollview里增加一个scrollview的xib的subview,编译的时候总是出现message sent to deallocated instance错误,百思不得其解。viewload的时候没问题,然后scroll就出问题了。
下面是具体代码。

storyboard的viewcontroller:


  • (void)viewDidLoad
    {
    [super viewDidLoad];

    self.Scrollview.frame = self.view.frame;
    self.Scrollview.contentSize = CGSizeMake(self.view.frame.size.width, self.Scrollview.frame.size.height);
    self.Scrollview.delegate = self;

    adViewController *adViewcontroller = [[adViewController alloc]init];
    adViewcontroller.view.frame = CGRectMake(0.0f, 60.0f, 320.0f, 150.0f);
    [self.Scrollview addSubview:adViewcontroller.view];

}


subview:

  • (void)viewDidLoad
    {
    [super viewDidLoad];

    UIView *page1 = [[UIView alloc]initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 150.0f)];
    page1.backgroundColor = [UIColor redColor];

    UIView *page2 = [[UIView alloc]initWithFrame:CGRectMake(320.0f, 0.0f, 320.0f, 150.0f)];
    page2.backgroundColor = [UIColor darkGrayColor];

    UIView *page3 = [[UIView alloc]initWithFrame:CGRectMake(320.0f * 2, 0.0f, 320.0f, 150.0f)];
    page3.backgroundColor = [UIColor greenColor];

    UIView *page4 = [[UIView alloc]initWithFrame:CGRectMake(320.0f * 3, 0.0f, 320.0f, 150.0f)];
    page4.backgroundColor = [UIColor blueColor];

    UIView *page5 = [[UIView alloc]initWithFrame:CGRectMake(320.0f * 4, 0.0f, 320.0f, 150.0f)];
    page5.backgroundColor = [UIColor whiteColor ];

    UIView *page6 = [[UIView alloc]initWithFrame:CGRectMake(320.0f * 5, 0.0f, 320.0f, 150.0f)];
    page6.backgroundColor = [UIColor purpleColor];

    self.ScrollView.delegate = self;

    [self.ScrollView addSubview:page1];
    [self.ScrollView addSubview:page2];
    [self.ScrollView addSubview:page3];
    [self.ScrollView addSubview:page4];
    [self.ScrollView addSubview:page5];
    [self.ScrollView addSubview:page6];

}

  • (void) scrollViewDidScroll: (UIScrollView *) aScrollView
    {
    CGPoint offset = aScrollView.contentOffset;
    self.pageController.currentPage = offset.x / 320.0f;
    }

  • (IBAction)changePage:(id)sender
    {
    [UIView animateWithDuration:0.3f animations:^{
    int whichPage = self.pageController.currentPage;
    self.ScrollView.contentOffset = CGPointMake(320.0f * whichPage, 0.0f);
    }];
    }

还没有人回应!

您的回应

你还未登陆,不能回应!登陆