我正在看这本书的一个教程:
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
但是,当我将此代码放入AppDelegate.m时,出现错误消息“对于'AppDelegate',没有可见的@interface声明了选择器'displayMessage'”,但是我正在遵循编写的代码。
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;
}
最佳答案
该消息告诉您您正在调用方法displayMessage:
,但尚未定义它。
您的书在13.1节中使用了此方法,但该节中没有此方法的定义,但是在第19.1节中可以找到合适的定义。该定义在警报中显示一个字符串。
高温超导
附录
本书中所有示例的完整资源都可用于download from GitHub。作者对您缺少的方法的定义是:
- (void) displayMessage:(NSString *)paramMessage
{
[[[UIAlertView alloc] initWithTitle:nil
message:paramMessage
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil] show];
}
您可能要下载完整的归档文件,因为其他示例似乎也不完整。