【问题标题】:Using delegate for ABPeoplePickerNavigationController使用 ABPeoplePickerNavigationController 的委托
【发布时间】:2012-08-03 21:16:55
【问题描述】:

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

但它不起作用,我的方法没有被调用。缺少什么?

【问题讨论】:

    标签: ios delegates uitabbarcontroller


    【解决方案1】:

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

    这样做以使其工作..

    contacts.peoplePickerDelegate = pickerDel;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-06
      • 2013-11-26
      • 2011-01-02
      • 2011-05-27
      • 2011-01-12
      相关资源
      最近更新 更多