[self performSelector:@selector(someMethod) withObject:nil afterDelay:1];
时间延迟之后连连调用一个方法。它工作正常,但我的问题是,即使我导航到下一个类,执行选择器正在运行在前一课的背景。
所以我尝试使用以下
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(someMethod) object:nil];
取消它,但它不工作。我在viewDidDisappear
。任何人都可以告诉我如何取消执行选择器?
这里是我的代码
-(void)textCalling
{
NSString *[email protected]"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];
}
尝试在viewWillDisappear .. –
是的,它的正确只有我们可以使用[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(someMethod)object:nil];或[NSObject cancelPreviousPerformRequestsWithTarget:self]; – Ann
我尝试viewWillDisappear也但它不工作... – Ann