2013-07-20 39 views
-3

的錯誤是: 「爲UIAlertView中無可見@interface聲明選擇 'initWithTitle:消息:委託:cancelButtonTitle:otherButtonTitle:'」爲 'UIAlertView中' 不可見@interface聲明選擇

- (void) subtractTime; 
{ 
    seconds --; 
    timerLabel.text = [NSString stringWithFormat:@"Time: %i", seconds]; 

    if(seconds == 0) 
    { 
     [timer invalidate]; 
     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Time is up !" 
           message: [NSString stringWithFormat: @"You Scored %i points", count] 
           delegate:self 
           cancelButtonTitle: @"Play Again?" 
           otherButtonTitle:nil]; 
    } 
} 
@end 
+2

當您看到該消息並且您知道該方法應該存在時,您應該始終仔細查看代碼:您拼寫的方法名稱錯誤。 – Caleb

回答

4

你有代碼中的錯字。

它應該是:

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Time is up !" 
               message: [NSString stringWithFormat: @"You Scored %i points", count] 
               delegate:self 
             cancelButtonTitle: @"Play Again?" 
             otherButtonTitles:nil]; 

請注意,這是 「otherButtonTitles」,而不是 「otherButtonTitle」。

+0

謝謝你,不幸的是它並沒有解決主要錯誤。我不知道它是什麼意思,「沒有可見的@Interface UIAlertView」 – user2602189

+0

@ user2602189:不,這確實解決了你所看到的錯誤。該消息告訴您,編譯器無法在類的頭中找到具有該名稱的方法,這通常是由拼寫錯誤造成的。如果您仍然收到錯誤消息,則說明您沒有正確實施修復程序,或者您現在遇到了不同的錯誤。 – Chuck

+0

@ user2602189如果你仍然看到錯誤,也許你必須用'#import '手動導入UIKit頭。請注意,UIAlertView通常只在iOS上可用。如果您正在爲Mac開發,您將無法使用它。 – howanghk

相關問題