代码之家  ›  专栏  ›  技术社区  ›  Tirth

使用NSTimer调用方法时出现问题?

  •  0
  • Tirth  · 技术社区  · 14 年前

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

    上面的内容不起作用。为什么?

    #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 回复  |  直到 14 年前
        1
  •  1
  •   Jacob Relkin    14 年前

    您的选择器定义不正确。

    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];
    

    NSTimer NSObject 更多细节请参考。

        2
  •  0
  •   Nick Hingston    14 年前

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

    您的方法原型还需要:

    - (void) imageViewAnimation:(NSTimer*) timer