I'm working on animating little subviews throughout my UI using a flip transition. To get the Flip transition to work correctly, I create a temporary UIView to provide the context, run the transition, and then need to clean up afterwards. But I'm having trouble figuring how to release the object without crashing the application. Here's the code block:
UIView *tempContainer = [UIView alloc];
tempContainer = [self.view viewWithTag:700];
[UIView transitionWithView:tempContainer
duration:2
options:UIViewAnimationOptionTransitionFlipFromRight
animations:^{
[[[tempContainer subviews] objectAtIndex:0] removeFromSuperview];
[tempContainer addSubview:newImageView];
[newImageView release];
}
completion:^(BOOL finished){
[tempContainer release]; //Crashes app
}];
I'm using block-based animation techniques for iOS4. The problem is that my tempContainer is definitely leaking, but if I release or autorelease it in the completion block, my app crashes, and I do it after the [UIView transition...] message, it crashes. What's the best way to refactor this so I don't leak out my memory? (I have 30 of these little things to do.)