views:

56

answers:

1

I have a NSTimer running in a subview of a view. I want to remove the view and of course stop the timer. I seem to be able to remove the view (it physically disappears) but the timer keeps running, I can see the trace statements still.

This is the code to remove the view...

for (UIView *subview in [self.myViews subviews]) {
    NSLog(@"*****REMOVE current views!!!!!!!!!!!!");
       // Only remove the subviews with tag not equal to 1
    if (subview.tag != 1) {
     NSLog(@"*****!!!");
     [subview removeFromSuperview];
    }
+1  A: 

Did you try [timer invalidate] right after [subview removeFromSuperview]?

thyrgle
The timer is in the subview so it should no longer exist? I'm new to this so i could be completely wrong. Surely removing the view should remove the timer?
@user157733: The timer is just a timer its not view dependent.
thyrgle
oh i see, i didn't realise that. How do i access the timer in the subview then? I tried invalidating it in the subview in...viewDidUnload but it never gets called.
@user157733: Um... I would need to see more code than what you have to tell you what is going on.
thyrgle