我需要在 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
但它不起作用,我的方法没有被调用。什么不见了?