2010-10-04 56 views
0

我想在特定的時間後只調用一次方法,因此我寫了一個如下的語句。使用NSTimer調用方法的問題?

imageAnimationTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector([self imageViewAnimation:imageViewObject]) userInfo:nil repeats:NO]; 

以上將不會工作。爲什麼? 它給了我一些奇怪的問題。 我如何調用和使用的NSTimer沿與發送的參數是:scheduledTimerWithTimeInterval:目標:選擇:用戶信息:重複:

#0 0x02911732 in __kill() 
#1 0x02911724 in kill$UNIX2003() 
#2 0x029a498d in raise() 
#3 0x029baa44 in abort() 
#4 0x0330bfda in __gnu_cxx::__verbose_terminate_handler() 
#5 0x02ccd61c in _objc_terminate() 
#6 0x0330a17a in __cxxabiv1::__terminate() 
#7 0x0330a1ba in std::terminate() 
#8 0x0330a2b8 in __cxa_throw() 
#9 0x02ccd3d8 in objc_exception_throw() 
#10 0x02bb4a5b in -[NSObject doesNotRecognizeSelector:]() 
#11 0x02b31676 in ___forwarding___() 
#12 0x02b30a32 in __forwarding_prep_1___() 
#13 0x000055af in -[StageOneForSuspectOne imageViewAnimation:] (self=0x6182a70, _cmd=0x6fda, imageView=0x618c570) at /Users/ajm/Desktop/ProgramOne/Classes/StageOne.m:218 
#14 0x0004cffd in __NSFireTimer() 
#15 0x02b027dc in CFRunLoopRunSpecific() 
#16 0x02b018a8 in CFRunLoopRunInMode() 
#17 0x0352289d in GSEventRunModal() 
#18 0x03522962 in GSEventRun() 
#19 0x002d1372 in UIApplicationMain() 
#20 0x000028ec in main (argc=1, argv=0xbffff074) at /Users/ajm/Desktop/DetectiveJone/main.m:14 
(gdb) 

回答

1

你的選擇是錯誤的定義。

imageAnimationTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(imageViewAnimation:) userInfo:imageViewObject repeats:NO]; 

我會簡單地使用performSelector:withObject:afterDelay:

[self performSelector:@selector(imageViewAnimation:) withObject:imageViewObject afterDelay:1.0]; 

退房的NSTimerNSObject參考更多詳細信息建議。

+0

我也寫同一行代替我的問題,但它仍然給我錯誤(應用程序有_kill問題)的NSTimer。 – Tirth 2010-10-04 15:17:13

+0

@rajB,請詳細說明。 – 2010-10-04 15:18:17

+0

我正在更新控制檯返回跟蹤錯誤。 – Tirth 2010-10-04 15:42:51

0

除了Jacobs的評論(你想仍然使用的NSTimer - 你可能需要使用的NSTimer一個原因是可以取消):

imageAnimationTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(imageViewAnimation:) userInfo:imageViewObject repeats:NO]; 

你的方法原型也需要:

- (void) imageViewAnimation:(NSTimer*) timer 

我的猜測是你有這個錯誤也...雖然沒有堆棧跟蹤&控制檯輸出,只是猜測。