我在iOS 7上使用+[NSTimer scheduledTimerWithTimeInterval:invocation:repeats]
時遇到了崩潰。代碼很簡單;這裏是複製粘貼(帶有變量重命名)。NSTimer + NSInvocation導致iOS 7崩潰
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
。不幸的是,崩潰依然存在。
在此先感謝!
謝謝!這工作。我應該更仔細地閱讀文檔。 :) –
當然......... :) –