This is my first time posting and I am stuck on what is sure to be an easy question. I am using a framework that causes snow to fall over a UIImage that is chosen by the user. Here is the code that creates an instance of the snowfalling class:
- (void)viewDidAppear:(BOOL)animated
{
// Animate
SnowFalling *snowfalling = [[SnowFalling alloc]
initWithView:self.view];
snowfalling.hidden = NO;
snowfalling.numbersOfFlake = 175;
[snowfalling startAnimating];
}
After this, I want to pop back to the previous view using a custom back button:
// Custom back button on toolbar.
- (IBAction)backButton:(UIBarButtonItem *)sender {
[[self navigationController] popViewControllerAnimated:YES];
}
This works fine accept that when I hit the back button, the app crashes with a zombie that says: “[uiview frame] message sent to deallocated object”
If I place:
[snowfalling stopanimating];
in the snowfalling instance, than the current view controller just has the snow frozen on the screen. But it will let me pop to the previous controller with no issue.
My question then is, how do I stop the animation when the back button (popViewControllerAnimated:YES) is hit?
In you controller class create a property to hold the value of snowfalling:
In your viewDidAppear: assign the newly created SnowFalling to that property instead of the local variable.
Remember to [release] SnowFalling right after assigning it to the property. The whole method should look like this:
In [backButton:] call
before calling popViewControllerAnimated. Better yet, place these two lines in [viewWillDisappear:], that way they will always get invoked.