使用NSTimer的调用方法有问题吗?

时间:2010-10-04 15:00:48

标签: iphone

我想在特定时间之后调用该方法一次,因此我写了一个声明如下。

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

以上将无法使用。为什么? 它给了我一些奇怪的问题。 我如何使用NSTimer调用和发送参数:scheduledTimerWithTimeInterval:target:selector:userinfo:repeats:

#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) 

2 个答案:

答案 0 :(得分: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参考资料,了解更多详情。

答案 1 :(得分:0)

除了雅各布的评论(你想仍然使用NSTimer - 你可能想要使用NSTimer的一个原因是你可以取消它):

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

您的方法原型也需要:

- (void) imageViewAnimation:(NSTimer*) timer

我的猜测是你也有这个错误...虽然没有堆栈跟踪&控制台输出,只是猜测。