objective-c - 如何消除 <Class> 可能无法响应 <Selector> 的警告?

标签 objective-c iphone cocoa cocoa-touch

下面的代码的行为符合预期,但是编译器不断告诉我这一点: 警告:“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/

相关文章:

macos - 如何在不关闭窗口的情况下关闭文档?

iphone - 是否可以在安装 Xcode 4 后安装 Xcode 3?

iphone - iOS - 无法加载表格 View

ios - 通过 Xcode 意外覆盖了 iPhone 设备位置

ios - Game Center Sandbox 中缺少邀请

objective-c - 如何创建自定义 NSMenuItem

objective-c - Objective-C 中的星号用法 : related questions

objective-c - 具有标量返回值的 Objective C 选择器不可用

Objective-C::使用方法来改变对象

iphone - UIImageView 中的边框