1
我需要管理UITabBarController中的ABPeoplePickerNavigationController(我不想以模態方式顯示ABPeoplePickerNavigationController,因爲我想保持tabbar可見)。然後,我用這個代碼來設置的UITabBarController:使用委託給ABPeoplePickerNavigationController
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
但它不起作用,我的方法不叫。什麼不見了?
wooooow!非常感謝 :) – 2013-02-13 07:43:31