Objective-C Address Book

I have two Objective-C classes that inherit from UIViewController, and I'm trying to use a different approach when learning how to interact with the iPhone address book. Example Apple suggests that everything is in the same class, but that’s not how I need it. My goal would be to close the address book after selecting a person. Please take a look and let me know how I can do this without having a CallerClass to implement ABPeoplePickerNavigationControllerDelegate. Thanks!

- change -

This seems to be boiling up to [self rejectModalViewControllerAnimated: YES]; has no effect in CalleeClass.m. It seems I still can’t answer to close the address book from this command.

CallerClass.m

#import "CallerClass.h"

@implementation CallerClass
- (IBAction)openAddressBook {
    CalleeClass *cc = [[CalleeClass alloc] init];
    [self presentModalViewController:[cc doIt] animated:YES];
}

CalleeClass.h

#import <UIKit/UIKit.h>
#import <AddressBook/AddressBook.h>
#import <AddressBookUI/AddressBookUI.h>

@interface CalleeClass : UIViewController <ABPeoplePickerNavigationControllerDelegate> {
    NSString *name;
}

-(ABPeoplePickerNavigationController *)doIt;

@property (nontoxic, retain) NSString *name;

@end

CalleeClass.m

#import <UIKit/UIKit.h>
#import <AddressBook/AddressBook.h>
#import <AddressBookUI/AddressBookUI.h>
#import "CalleeClass.h"

@implementation CalleeClass
@synthesize name;

... ( ABPeoplePickerNaviationControllerDelegate , )

- (id)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {}
    return self;
}

- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person {
    self.name = (NSString *)ABRecordCopyValue(person,kABPersonAddressProperty);

    [self dismissModalViewControllerAnimated:YES];
    return NO;  
}

-(ABPeoplePickerNavigationController *)doIt {
    ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
    picker.peoplePickerDelegate = self;
    return picker;
}

@end
+3
2

, [self dismissModalViewControllerAnimated:YES] , CalleeClass, , dismissModalViewControllerAnimated: (.. , presentModalViewController:Animated:. CallerClass CalleeClass, .

, dismissModalViewControllerAnimated::

, , .

, :

- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person {
    self.name = (NSString *)ABRecordCopyValue(person,kABPersonAddressProperty);
    [peoplePicker dismissModalViewControllerAnimated:YES];
    return NO;  
}
+1

, , int32, , API, , , , recordID - , "1", , ​​ recordID. , - , , , recordID , , , . , , , , , . , .

0

Source: https://habr.com/ru/post/1720827/


All Articles