1

ViewControllerUIButton

- (IBAction)buttonPressed:(id)sender {
    FirstTopViewController *controller = [[FirstTopViewController alloc]init];
    controller = [self.storyboard instantiateViewControllerWithIdentifier:@"Upper"];
    controller.view.frame = CGRectMake(300,0, 320, 460);


    [UIView animateWithDuration:0.5
                          delay:0.1
                        options: UIViewAnimationCurveEaseIn
                     animations:^{
                         controller.view.frame = CGRectMake(20, 0, 320, 460);
                     }
                     completion:^(BOOL finished){
                     }];
      [self.view addSubview:controller.view];
}

在这里,我将 newViewController 添加为MenuViewController.

FirstViewController与_UIButton

- (IBAction)backToMain:(id)sender {
    [UIView animateWithDuration:1.5
                          delay:0.5
                        options: UIViewAnimationCurveEaseIn
                     animations:^{
                         self.view.frame = CGRectMake(0, 490, 320, 460);
                     }
                     completion:^(BOOL finished){
                     }];
}

ISSUE 当我按下它上的按钮时,MenuViewController它会完美地呈现FirstViewController为带有动画的子视图,但是当我按下它时,FirstViewController它会崩溃

-[FirstViewController performSelector:withObject:withObject:]: message sent to deallocated instance 0x8a6efc0 

请查阅。

4

2 回答 2

1

设为FirstTopViewController *controller类级别变量。问题是控制器对象是本地的,并且在 btn_funtion 完成后被释放。然后,当您点击按钮时,它会向已释放的实例发送消息。

于 2013-06-13T07:15:48.777 回答
0

只需在 MenuViewController 的 .h 文件中创建 FirstViewController 的实例。现在您的 FirstViewController 的实例将由 parentview 持有。

于 2015-02-13T10:32:12.393 回答