I am using
[self performSelector:@selector(someMethod) withObject:nil afterDelay:1];
to call a method again and again after a time delay. It’s Working fine but my problem is, even though I navigate to next class, perform selector is running background in the previous class.
So I try to cancel it by using the following
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(someMethod) object:nil];
but it’s not working. I did this in viewDidDisappear. Can anyone tell me how to cancel perform selector?
Here is my code
-(void)textCalling
{
NSString *str2=@"Something";
UILabel *lbl =(UILabel*)[arrObj objectAtIndex:count2];
[lbl setAlpha:0];
lbl.numberOfLines=0;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
lbl.text=str2;
[UIView setAnimationDuration:0.0];
[lbl setAlpha:0];
[UIView commitAnimations];
}
-(void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
{
UILabel *lbl =(UILabel*)[arrObj objectAtIndex:count2];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:2.0];
[lbl setAlpha:1];
[UIView commitAnimations];
count2++;
if (count2<[arrCourse count]) {
[self performSelector:@selector(textCalling) withObject:nil afterDelay:1];
}else{
count2=0;
[self performSelector:@selector(imageCallingCourse) withObject:nil afterDelay:1];
}
}
-(void)imageCallingCourse
{
imgViewObj.image=[UIImage imageNamed:@"Objective.png"];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationDidStopImageCourse:finished:context:)];
[UIView setAnimationDuration:0.0];
[imgViewObj setAlpha:0];
[UIView commitAnimations];
}
-(void)animationDidStopImageCourse:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
{
NSLog(@"animationDidStopImage1");
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:2.0];
[imgViewObj setAlpha:1];
[UIView commitAnimations];
}
In .h,
In .m viewWillAppear,
In viewWillDisappear,
then,
so after changing the view the code after return in method wiil not excecute..