1

私はViewController一緒に持っていますUIButton

- (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 を の subView として追加しMenuViewControllerます。

一緒FirstViewControllerUIButton

- (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新しく表示されますが、ボタンを押すとクラッシュしますFirstViewControllerFirstViewController

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

見直してください。

4

2 に答える 2

1

FirstTopViewController *controllerクラス レベル変数として作成します。問題は、コントローラ オブジェクトがローカルであり、btn_funtion の実行後に割り当てが解除されることです。次に、ボタンをタップすると、割り当てが解除されたインスタンスにメッセージが送信されます。

于 2013-06-13T07:15:48.777 に答える