[英]No visible @interface for 'AppDelegate' declares the selector 'displayMessage'
i'm following a tutorial from this book: 我正在看这本书的一个教程:
http://books.google.co.uk/books?id=6WtVAQAAQBAJ&pg=PA569&lpg=PA569&dq=%5Bself+displayMessage:+kDenied%5D&source=bl&ots=PSj5Nu_QyI&sig=VHOeJtYHARgMOqSEdREyCtcgxc8&hl=en&sa=X&ei=b2rxUv-iN4WQhQfwxIGYDQ&ved=0CC0Q6AEwAA#v=onepage&q=%5Bself%20displayMessage%3A%20kDenied%5D&f=false http://books.google.co.uk/books?id=6WtVAQAAQBAJ&pg=PA569&lpg=PA569&dq=%5Bself+displayMessage:+kDenied%5D&source=bl&ots=PSj5Nu_QyI&sig=VHOeJtYHARgMOqSEdREyCtcgxc8&hl=en&sa=X&ei=b2rxUv-iN4WQhQfwxIGYDQ&ved=0CC0Q6AEwAA#v= onepage&q =%5Bself%20displayMessage%3A%20kDenied%5D&F =假
But when I put this code into AppDelegate.m I get the error message "No visible @interface for 'AppDelegate' declares the selector 'displayMessage'", however i'm following the code as it is written. 但是,当我将此代码放入AppDelegate.m时,出现错误消息“'AppDelegate'的无可见@interface声明了选择器'displayMessage'”,但是我正在遵循编写的代码。
CFErrorRef error = NULL; CFErrorRef错误= NULL;
switch (ABAddressBookGetAuthorizationStatus()) {
case kABAuthorizationStatusAuthorized:{
addressBook = ABAddressBookCreateWithOptions(NULL, &error);
[ self useAddressBook:addressBook];
// Do you work and once your finished..
if (addressBook != NULL) {
CFRelease(addressBook);
}
break;
}
case kABAuthorizationStatusDenied:{
[self displayMessage: kDenied];
break;
}
case kABAuthorizationStatusNotDetermined:{
addressBook = ABAddressBookCreateWithOptions(NULL, &error);
ABAddressBookRequestAccessWithCompletion
(addressBook, ^(BOOL granted, CFErrorRef error)
{
if (granted){
NSLog(@"Access was granted");
[self useAddressBook:addressBook];
} else {
NSLog(@"Access was not granted");
}
if (addressBook != NULL){
CFRelease(addressBook);
}
});
break;
}
case kABAuthorizationStatusRestricted:{
[self displayMessage: kRestricted];
break;
}
}
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
} }
You're calling the following instance method: 您正在调用以下实例方法:
[self displayMessage: kRestricted];
Which isn't declared in your subclass of UIApplication (AppDelegate). 在您的UIApplication(AppDelegate)子类中未声明。
To solve this, just implement the displayMessage:
method: 要解决此问题,只需实现
displayMessage:
方法:
- (void)displayMessage:(id)message
{
// do stuff here
}
The message is telling you that you are calling the method displayMessage:
and you have not defined it. 该消息告诉您您正在调用方法
displayMessage:
但尚未定义它。
Your book is using this method in section 13.1 but there is no definition of it in that section, however what looks like a suitable definition can be found in section 19.1. 您的书在13.1节中使用了此方法,但该节中没有此方法的定义,但是在第19.1节中可以找到合适的定义。 That definition displays a string in an alert.
该定义在警报中显示一个字符串。
HTH HTH
Addendum 附录
The full source of all the examples in the book is available for download from GitHub . 本书中所有示例的完整资源均可从GitHub下载 。 The author's definition of your missing method is:
作者对您丢失的方法的定义是:
- (void) displayMessage:(NSString *)paramMessage
{
[[[UIAlertView alloc] initWithTitle:nil
message:paramMessage
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil] show];
}
You might want to download the full archive as it looks like other examples may be incomplete as well. 您可能要下载完整的存档,因为其他示例似乎也不完整。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.