Pradheep Narendran P February 2016

UIView contains NSTimer - not releasing

I'm using one UIView subclass that has some CAAnimation which would be performed after performsegue from another class. In the UIView class, I'm using CADisplayLink and NSTimer to increment the CATextLayer used in the animation. Whenever, I came back to the previous view controller after running the animation, it keeps on running in the background. When I go to View controller where the animation is playing, it shows me incorrect count. Is there anything wrong with my code ?

In the .h file,

@property (assign,nonatomic) CFTimeInterval duration;
@property (nonatomic,strong) NSTimer *tim1;
@property (nonatomic,strong) NSTimer *tim2;
@property (nonatomic,strong) NSTimer *tim3;
@property (nonatomic,strong) NSTimer *startup;
@property (nonatomic,strong) NSTimer *starter;
@property (nonatomic,strong) NSTimer *suspender;
@property (nonatomic,strong) NSTimer *humansum;
@property (nonatomic,strong) NSTimer *transportsum;
@property (nonatomic,strong) NSTimer *wastesum;
@property (nonatomic,strong) NSTimer *watersum;
@property (nonatomic,strong) NSTimer *energysum;
@property (nonatomic,strong) NSTimer *humanslowsum;
@property (nonatomic,strong) NSTimer *transportslowsum;
@property (nonatomic,strong) NSTimer *wasteslowsum;
@property (nonatomic,strong) NSTimer *waterslowsum;
@property (nonatomic,strong) NSTimer *energyslowsum;
@property (nonatomic,strong) CADisplayLink  *displayLink;

In the .m file, //Below code is called inside a method

displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(tick:)];
[displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];

- (void)tick:(CADisplayLink *)sender
{
    duration = sender.duration;
 startup=[NSTimer scheduledTimerWithTimeInterval:(2+(0.05*duration)) target:self selector:@selector(calltheanimating_function) userInfo:nil repeats:NO];

 if(initil==YES){
        //
            humansum  =[NSTimer scheduledTimerWithTimeInterval:(15.        

Answers


Pradheep Narendran P February 2016

Finally, found an answer by simple method. Creating an IBOutlet of the uiview subview inside super view and invalidating the NSTimer(s) over there while performing segue.

Post Status

Asked in February 2016
Viewed 2,310 times
Voted 13
Answered 1 times

Search




Leave an answer