2013-01-18 49 views
1

我在用Objective-C的第三版閱讀O'Reilly出版的學習可可過程錯誤:「對‘UIAlertView中’不可見@interface聲明選擇‘initWithTitle’

O'Reilly的網站。 。沒有這種特定圖書的論壇,並搜索出該錯誤不返回任何

在第18頁,我不斷收到以下錯誤:

"No visible @interface for 'UIAlertView' declares the selector 'initWithTitle:message:deluge:cancelButtonTitle:otherButton'" 

這裏是我的代碼:

// 
// ViewController.m 
// HelloCocoa 
// 
// Created by ME on 1/14/13. 
// Copyright (c) 2013 ME. All rights reserved. 
// 

#import "ViewController.h" 

@interface ViewController() 

@end 

@implementation ViewController 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 
} 

- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 

- (IBAction)showAlert:(id)sender 
{ 
    UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Hello!" 
                message:@"Hello, World!" 
                delegate:nil 
              cancelButtonTitle:@"Close" 
              otherButtonTitle:nil]; 
    [alert show]; 
    [_helloButton setTitle:@"I was Clicked!" forState:UIControlStateNormal]; 
} 
@end 



// 
// ViewController.h 
// HelloCocoa 
// 
// Created by ME on 1/14/13. 
// Copyright (c) 2013 Andrew DiNatale. All rights reserved. 
// 

#import <UIKit/UIKit.h> 

@interface ViewController : UIViewController 
@property (strong, nonatomic) IBOutlet UIView *helloButton; 
- (IBAction)showAlert:(id)sender; 
@end 

什麼原因導致此錯誤?

+0

我不知道它是否是一個錯字,但是您的選擇器讀取'initWithTitle:message:deluge:cancelButtonTitle:otherButton'。洪水? – CodaFi

+0

對不起,這是一個錯字,你可以從代碼中看到我有它不同。我試圖糾正標題,但我不能... – Drewdin

回答

4

otherButtonTitles參數是複數(如在otherButtonTitle*s*中)。

+0

謝謝,這修復了錯誤,但現在我有第二個。 「沒有Vivible @interface for'UIView'聲明選擇器'setTitle:forState:'」。有什麼建議麼? – Drewdin

+0

將'helloButton'聲明爲UIButton。這個教程多少歲? – CodaFi

+0

它於2012年12月發佈,迄今爲止我並沒有預料到會出現這麼多錯誤......對於我的無知,我不知道如何將其聲明爲UIButton?現在我只是將按鈕拖入.h文件並添加了i書中的代碼。我還什麼都不知道。 – Drewdin

0

UIAlertView是一個UIKit(iOS)類。看起來你正在嘗試在Cocoa項目中使用它,而不是Cocoa Touch。

+1

他會在.m之前得到更多的錯誤,如果他試圖編譯這個OS X – CodaFi

+0

我創建了一個IOS單視圖應用程序。我添加的所有內容都是顯示器和上述代碼的按鈕。謝謝 – Drewdin

0

我是本書的作者之一。

這個問題已經得到了正確的回答,但我只是想提醒--CodaFi的答案是正確的,問題是該方法以「otherButtonTitles」(帶有s)而不是「otherButtonTitle」結尾。

我只是仔細檢查了本書的第18頁,它實際上看起來就像書本里有它正確!

如果您對本書有任何其他疑問,請在此發帖 - 我會四處流動,尋找任何提及本書的問題。勘誤總是值得歡迎的!

+0

我複製了這個問題,它告訴你將按鈕拖到書中的代碼頁。出於某種原因,當我第一次做它時,它沒有正確填充。我刪除了代碼,並再次移動它,它工作正常。感謝您的跟進 – Drewdin

相關問題