更改ABPeoplePickerNavigationController属性

时间:2013-04-02 08:30:18

标签: objective-c

我正在尝试更改联系人表格的某些属性,但我不能。 首先,我需要删除取消按钮并改为设置“添加”按钮。我已尝试使用委托方法将其设置为nil,但它没有用。

唯一可行的方法是:

 [picker setAllowsCancel:NO];

发出警告:(我不想承担风险)

instance method not found

我还需要删除“群组”按钮。

所以在底线,我想删除上方栏中的所有按钮,并设置我自己的按钮。我该怎么做?

谢谢。

1 个答案:

答案 0 :(得分:0)

Rant,你不能使用方法:

[picker setAllowsCancel:NO];

这是Apple的私人API(非公开),他们会拒绝您的应用。

ABPeoplePickerNavigationController *tempABPNC = [[ABPeoplePickerNavigationController alloc] init];
tempABPNC.peoplePickerDelegate = self;
tempABPNC.delegate = self;
[self presentModalViewController:tempABPNC animated:YES];
[tempABPNC release];

你必须添加“tempABPNC.delegate = self;”然后实现UINavigationControllerDelegate方法:

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated{
viewController.title = @"选择联系人";
tinlnTempVC = viewController;
viewController.navigationItem.leftBarButtonItem = nil;
UIViewController *tempABVC = [navigationController.viewControllers lastObject];
tempABVC.title = @"选择联系人";
if([viewController.view.subviews count]==0){ //if user disable app open contact,you can create your own view,
    UIView *tempV=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, IS_IPHONE5 ? 504 : 416)];
    ...
    ...
    viewController.view = tempV;
    [tempV release];
}}

在这个viewcontroller中,子类ABPeoplePickerNavigationController,所以我们可以用我们自己的按钮替换navigationleft,right,backitem

static UIViewController *tinlnTempVC;
@implementation ABPeoplePickerNavigationController (tinlnCustom)

- (void)viewWillLayoutSubviews{
if ([[[UIDevice currentDevice] systemVersion] floatValue] < 5.0)
    return;
UIButton *dismisBtn = [UIButton DIYNavigationBarItemBtnWithTitle:@"返 回" NC:tinlnTempVC.navigationItem];
[dismisBtn addTarget:self action:@selector(backToPayPhone) forControlEvents:UIControlEventTouchUpInside];}

- (void)backToPayPhone{
[self dismissModalViewControllerAnimated:YES];}


@end

希望帮助你,Rant,iOS 5.0-6.1中的这种方法运行完美,在iOS 4.3-5.0中,backitem在第一次显示时无法取代。