2009-09-24 27 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的定義,並沒有得到保證(通過看頭文件中的方法簽名的聲明)存在這樣的定義。因此它會警告您,您嘗試呼叫的方法可能不存在。