NSTimer有效生产sigabrt

时间:2011-12-09 14:52:11

标签: iphone objective-c ios xcode sigabrt

if([timer isValid])  // << breakpoint here
{
    NSLog(@"Timer Valid");
}
timer = [NSTimer scheduledTimerWithTimeInterval:[timeinterval intValue] target:self selector:@selector(PlayDelaySound) userInfo:nil  repeats:NO];

第一次未安排timer时,该功能正常运行。但是,对于后续调用,在调试时,控制台会给我记录单步执行的日志(如下所示)。然后给sigabrt。

有什么帮助吗? 感谢

日志

Single stepping until exit from function objc_msgSend, 
which has no line number information.
warning: Remote failure reply: E37
Single stepping until exit from function objc_msgSend, 
which has no line number information.
warning: Remote failure reply: E37

1 个答案:

答案 0 :(得分:4)

也许你错过了retain

像这样:

timer = [[NSTimer scheduledTimerWithTimeInterval:[timeinterval intValue] target:self selector:@selector(PlayDelaySound) userInfo:nil  repeats:NO]
         retain];

更新:因为如果您不保留,可能会在某个时间释放计时器实例,并且您对isValid的调用会导致崩溃。