下面的代码的行为符合预期,但是编译器不断告诉我这一点: 警告:“StatusViewController”可能不会响应“-beginLoadingThreadData”
我如何摆脱这个警告,最重要的是为什么 xcode 认为是这种情况?
这是我的代码:
[self beginLoadingThreadData]; // called in the loadDidView block
- (void)beginLoadingThreadData
{
[NSThread detachNewThreadSelector:@selector(loadThreadData) toTarget:self withObject:nil];
}
- (void)loadThreadData
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[NSThread sleepForTimeInterval:2];
[self performSelectorOnMainThread:@selector(finishedLoadingThreadData) withObject:nil waitUntilDone:NO];
[pool release];
}
- (void)finishedLoadingThreadData
{
[[BusinessLogic instance] startTracking:self];
}
最佳答案
在使用该方法之前先声明该方法。我假设它是一个私有(private)方法,在这种情况下,您可以在实现文件的顶部添加一个类扩展:
@interface MyClass ()
- (void) beginLoadingThreadData;
@end
如果它是公共(public)方法,请确保您已在 header 中声明该方法,并在实现文件顶部#import
该 header 。
关于objective-c - 如何消除 <Class> 可能无法响应 <Selector> 的警告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1474075/