나는 시간 지연 후 또 다시 메서드를 호출 취소하는 방법 이전에 선택기를 선택 하시겠습니까?
[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];
}
보기에서 시도하십시오 .Disappear .. –
예, 해당 항목 만 수정합니다. [NSObject cancelPreviousPerformRequestsWithTarget : 셀렉터 : @selector (someMethod) object : nil]; 또는 [NSObject cancelPreviousPerformRequestsWithTarget : self]; – Ann
viewWillDisappear도 시도했지만 작동하지 않습니다 ... – Ann