ios - 使用 ABPeoplePickerNavigationController 的委托(delegate)

标签 ios delegates uitabbarcontroller

我需要在 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

但它不起作用,我的方法没有被调用。什么不见​​了?

最佳答案

ABPeoplePickerNavigationController 的委托(delegate)属性是 peoplePickerDelegate 而不是 委托(delegate)

这样做以使其工作..

contacts.peoplePickerDelegate = pickerDel;

关于ios - 使用 ABPeoplePickerNavigationController 的委托(delegate),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11836119/

相关文章:

ios - 使用 Realm 获取被点击的单元格引用对象

performance - 优化-webkit-transform 性能的技巧?

iOS MKMapView 不接受大于 45.x 的纬度值?

ios - 具有许多 UIView 的单例服务

ios - 将 ViewController 推到 TabBarController 之上

ios - Admob 横幅请求时间

ios - tableView reloadData 不起作用,委托(delegate)方法

delegates - 为可以委托(delegate)的解析器借用检查器问题

ios - 在标签栏 Controller 中查看 Controller

ios - 在 ViewController 循环中隐藏/显示 TabBar