[英]error: "No visible @interface for 'UIAlertView' declares the selector 'initWithTitle'
我正在閱讀O'Reilly的書,學習可可與Objective-C第3版。
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
是什么導致了這個錯誤?
otherButtonTitles
參數是復數(如otherButtonTitle*s*
)。
UIAlertView是一個UIKit(iOS)類。 看起來你正試圖在Cocoa項目中使用它,而不是Cocoa Touch。
我是這本書的作者之一。
這個問題已經得到了正確回答,但我只是想插入--CodaFi的答案是正確的,問題是該方法以“otherButtonTitles”(帶有s)結束,而不是“otherButtonTitle”。
我只是仔細檢查了本書的第18頁,看起來這本書看起來是正確的!
如果你對這本書有任何其他問題,請在這里發帖 - 我會四處尋找,尋找提到這本書的任何問題。 勘誤總是受歡迎!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.