2009-09-24 65 views
0

下面的代码的行为与预期但是编译器不断告诉我: 警告:“StatusViewController”不能为“-beginLoadingThreadData”如何摆脱<Class>的警告可能不会响应<Selector>?

如何摆脱警告的也是最重要的,为什么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]; 
} 

回答

7

在使用它之前声明该方法。我假定这是一个私有方法,在这种情况下,你将在实现文件的顶部添加一个类扩展:

@interface MyClass() 
- (void) beginLoadingThreadData; 
@end 

如果它是一个公共方法,请确保您已经声明在头的方法和#import在实现文件的顶部标题。

+0

我必须检查3次,我看到了声明......不止一个应用程序我需要一位眼科医生 - 谢谢彼得! – amok 2009-09-24 21:13:06

1

你的viewDidLoad定义之前无论是移动的loadingThreadData定义,或由@end之前插入-(void)beginLoadingThreadData;在头文件中定义它StatusViewController,例如在头文件中(可能是StatusViewController.h)。

的原因是,如果你不这样做,编译的时候达到你的viewDidLoad方法,并认为调用beginLoadingThreadData,但目前还没有看到的beginLoadingThreadData的定义,并没有得到保证(通过看头文件中的方法签名的声明)存在这样的定义。因此它会警告您,您尝试呼叫的方法可能不存在。