0

I've facing an issue of push & pop my UIViewController. I've two UIViewControllers say A & B.

I have written an IBAction in which I pushing to B from A like,

B *bView=[[B alloc] initWithNibName:@"B" bundle:nil];
[UIView beginAnimations:@"animation" context:nil];
[UIView setAnimationDuration:0.7];
[self.navigationController pushViewController:bView animated:NO];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO];
[UIView commitAnimations];

[bView release]; //Problem is here, If I comment this line, it works fine! else it crashes after my some transitions from A [push] B, B [pop] A.

Now in B I've written an IBAction to pop to A like below

[UIView beginAnimations:@"animation" context:nil];
[UIView setAnimationDuration:0.7];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO];
[self.navigationController popViewControllerAnimated:NO];
[UIView commitAnimations];

I have also calling [super dealloc] from B

-(void) dealloc
{
   [super dealloc];
}

If I don't release bView it will not call dealloc, and may creates issues of memory.

Is this problem because of animation I applying?

I tried with all other ways like autorelease, set bView=nil; etc. but those won't work for me!

Any help, suggestion!

Hemang
  • 26,840
  • 19
  • 119
  • 186
  • There is no problem with [bView release]; There is something else which is wrong in your Class B code, you can use NSZombie to track where exactly the issue is. Or you can paste code for your class B. – rishi Jun 29 '12 at 06:05
  • NSZombie is enabled, it shows message that, `message sent to deallocated reference` – Hemang Jun 29 '12 at 06:08
  • it will show some memory address, on console you can use "po memory-address" and see which instance is causing this issue. – rishi Jun 29 '12 at 06:34

1 Answers1

1

Try releasing bView inside the animation completion block instead.

You can use old style + setAnimationDidStopSelector: or if you don't need to support pre iOS4 devices, you can use animation blocks animateWithDuration:delay:options:animations:completion:

prakash
  • 58,901
  • 25
  • 93
  • 115