그래서 NIPimer가있는 UIPopover가 있습니다. 다른 방법을 만들기 위해 다양한 BOOLS 및 속성이 있지만 지금은 중요하지 않습니다. 내가 알고 싶은 것은, popover의 부모 뷰가 사라졌을 때 타이머를 해제하고 무효화 할 수있는 방법이 있습니까? 무효화하고 타이머를 해제하는 클래스 메서드를 시도했지만 그들은 SIGABRT 및 EXC_BAD_ACCESS 경고를 주었다. 나는 타이머가 이미 무효 였을 때 dealloc에게 말하도록하는 것과 관련이 있다고 생각한다.UIPopover에서 NSTimer 중지
몇 가지 추가 요인 : 1. 타이머는 유효 기간을 유지해야하며 popover가 해제 될 때 할당됩니다. 2. 부모보기가 사라지면 타이머가 무효화되고 해제되어야합니다.
제안 사항?
CODE :
//@interface
NSTimer *clickTimer;
@property (nonatomic, retain) NSTimer *clickTimer;
//.m
- (IBAction)clickerPressed:(id)sender
{
if ([click isClicking] == YES) {
[clickTimer invalidate];
[clickTimer release];
clickTimer = nil;
// enable the idle timer when the clicking is turned off
[[UIApplication sharedApplication] setIdleTimerDisabled:NO];
[click setIsClicking:NO];
[clickerButton setBackgroundImage:[UIImage imageNamed:@"wood.png"] forState:UIControlStateNormal];
[clickerButton setTitle:@"Start" forState:UIControlStateNormal];
[clickStatus setText:[NSString stringWithFormat:@"%d",[click numberOfBeatsToDisplay]]];
[click setClickCount:0];
}
else {
// disable the idle timer while the metronome is clicking.
[[UIApplication sharedApplication] setIdleTimerDisabled:YES];
[click setIsClicking:YES];
[clickerButton setBackgroundImage:[UIImage imageNamed:@"wood.png"] forState:UIControlStateNormal];
[clickerButton setTitle:@"Stop" forState:UIControlStateNormal];
[[NSThread currentThread] setThreadPriority:1.0];
clickTimer = [[NSTimer scheduledTimerWithTimeInterval:[click clickRateInSeconds] target:self selector:@selector(click:) userInfo:nil repeats:YES]retain];
}
}
항상, dealloc 외부의 변수를 해제 할 때는 항상 nil로 설정하십시오. '[clickTimer release]; clickTimer = nil;' – Joe
편집 됨, 죄송합니다. –
CodaFi