0
viewWillAppear
메서드가 호출 될 때 타이머를 시작하고 싶습니다.타이머가 viewWillAppear 메서드에서 시작되지 않습니다.
완벽하게 작동하지만 이미 타이머가있는 현재보기에서 새보기를 누르면 문제가 발생합니다. 새 뷰를 팝업하고 viewWillAppear
을 호출 할 때 이전처럼 타이머를 다시 시작하고 싶습니다. 나는 대부분의 기술을 가지고 있지만 해결책을 찾을 수 없습니다.
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[NSThread detachNewThreadSelector:@selector(createTimer) toTarget:self withObject:self];
}
- (void)createTimer
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSRunLoop* runLoop = [NSRunLoop currentRunLoop];
gameTimer = [[NSTimer timerWithTimeInterval:1.00 target:self selector:@selector(timerFired:) userInfo:nil repeats:YES] retain];
[[NSRunLoop currentRunLoop] addTimer:gameTimer forMode:NSDefaultRunLoopMode];
timeCount = 360;
[runLoop run];
[pool release];
}
- (void)timerFired:(NSTimer *)timer
{
if(timeCount == 0)
{
[self timerExpired];
} else {
timeCount--;
if(timeCount == 0) {
[timer invalidate];
[self timerExpired];
}
}
timeLabel.text = [NSString stringWithFormat:@"%02d:%02d",timeCount/60, timeCount % 60];
}
- (void) timerExpired
{
//NSLog(@"Final == %@",arrayAnswers);
//NSLog(@"Attempt == %d",[arrayAnswers count]);
[gameTimer invalidate];
gameTimer = nil;
}
[코드 ** 관련 ** ** 부분을 표시] (http://mattgemmell.com/2008/12/08/what-have-you-tried/)하면 사람들이 귀하의 문제가 어디에 있는지 파악하십시오. – Ben
'[타이머 무효화]를 시도해 보셨습니까? ' – Bazinga
내가 할 수있는 모든 가능한 방법을 시도했지만 아직 해결책을 얻지 못했습니다 – iDhaval