在 iOS 7 上使用时我遇到了崩溃+[NSTimer scheduledTimerWithTimeInterval:invocation:repeats]
。代码很简单;这是完整的复制粘贴(带有变量重命名)。
SEL selector = @selector(callback);
NSMethodSignature *signature = [self methodSignatureForSelector:selector];
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];
[invocation setTarget:self];
[NSTimer scheduledTimerWithTimeInterval:0.5 invocation:invocation repeats:NO];
当计时器触发时,我的应用程序崩溃并显示以下堆栈跟踪:
我认为可能其中一个变量不再保留(尽管 NSTimer 的文档提到它保留了所有引用的参数),所以我强烈将所有变量保留到self
. 不幸的是,崩溃仍然存在。
提前致谢!