1

UITabBarController で ABPeoplePickerNavigationController を管理する必要があります (タブバーを表示したままにするため、ABPeoplePickerNavigationController をモーダルに表示したくありません)。次に、このコードを使用して UITabBarController をセットアップします。

AppDelegate.m ファイル:

#import "PickerDelegate.h"

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    ABPeoplePickerNavigationController *contacts = [[ABPeoplePickerNavigationController alloc] init];
    PickerDelegate *pickerDel = [[PickerDelegate alloc] init];
    contacts.delegate = pickerDel;

    NSArray *aViewControllers = [NSArray arrayWithObjects:xvc, contacts, yvc, zvc, nil];

    UITabBarController *tabBarController = [[UITabBarController alloc] init];
    [tabBarController setViewControllers:aViewControllers];
    [xvc release];
    [contacts release];
    [yvc release];
    [zvc release];

    [window setRootViewController:tabBarController];
    [tabBarController release];
    [self.window makeKeyAndVisible];

    return YES;
}

PickerDelegate.h ファイル

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

@interface PickerDelegate : NSObject <UINavigationControllerDelegate, ABPeoplePickerNavigationControllerDelegate>

@property (nonatomic, assign) PickerDelegate *delegate;

-(void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker;
-(BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person;
-(BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier;

@end

そして最後に、 PickerDelegate.m ファイル:

#import "PickerDelegate.h"

@implementation PickerDelegate

@synthesize delegate = _delegate;

#pragma mark ABPeoplePickerNavigationControllerDelegate methods

// Displays the information of a selected person
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person
{
     NSLog(@"shouldContinueAfterSelectingPerson");

     //...
     return YES;
}

- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier
{
    NSLog(@"shouldContinueAfterSelectingPerson");

    //...
    return NO;
}

-(void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker
{
    NSLog(@"peoplePickerNavigationControllerDidCancel");

     //...
}
@end

しかし、うまくいきません。私のメソッドは呼び出されません。何が欠けている?

4

1 に答える 1

7

ABPeoplePickerNavigationController のデリゲート プロパティは peoplePickerDelegate であり、デリゲートではありませ

これを実行して機能させます..

contacts.peoplePickerDelegate = pickerDel;
于 2012-10-29T08:41:03.057 に答える