1

I Have ViewController with 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];
}

As here i add newViewController as subView of MenuViewController.

On FirstViewController with 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 When i pressed button on MenuViewController it present new FirstViewController as subView with animation perfectly but when i pressed Button on FirstViewController it is Crashing with

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

Please review.

Buntylm
  • 7,345
  • 1
  • 31
  • 51

2 Answers2

1

Make FirstTopViewController *controller as class level variable. Problem is controller object is local and gets deallocated after that btn_funtion is done. Then when you tap button it sends message to a deallocated instance.

Durgaprasad
  • 1,910
  • 2
  • 25
  • 44
0

Just create an instance of FirstViewController in MenuViewController's .h file. And now your FirstViewController's instace will be hold by parentview.

utkal patel
  • 1,321
  • 1
  • 15
  • 24