i'm following a tutorial from this book:
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.
CFErrorRef error = 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).
To solve this, just implement the displayMessage:
method:
- (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.
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. That definition displays a string in an alert.
HTH
Addendum
The full source of all the examples in the book is available for download from 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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.