iphone - NSTimer 可有效生成 sigabrt

标签 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

最佳答案

也许您缺少一个retain

像这样:

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

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

关于iphone - NSTimer 可有效生成 sigabrt,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8447250/

相关文章:

iphone - 如何为 iPhone 项目设置 PayPal Live App ID?

iphone - MVC 中的 View 应该有自己的类吗?

iPhone - 在本地和生产环境设置之间切换

ios - Dart devtools内存 View 无法使用堆栈溢出错误

ios - UITabBarController 和 UINavigationController - 选项卡单击并显示特定 Controller

iphone - iPhone 中的多行文本字段

objective-c - NSView 上以椭圆为内容的鼠标事件

objective-c - 在 PC 上为 iPhone 开发?

ios - 我需要运行 XCode 4.3 项目两次才能启动 cocos2d 应用程序

ios - FBSDKAppInviteDialog 不工作