1

我想删除 ABPeoplePickerNavigationController 导航栏中的取消按钮,因为我想要一个添加按钮。我以这种方式自定义了导航控制器委托:

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated{


switch ([navigationController.viewControllers count]) {

    case 0: {

        viewController.navigationItem.rightBarButtonItem = nil;
        break;

    }

    case 1: {

        viewController.navigationItem.rightBarButtonItem = nil;
        break;
    }

    case 2: {



        UIBarButtonItem *addButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addPerson:)];
        [viewController.navigationItem setRightBarButtonItem:addButtonItem animated:NO];
        [addButtonItem release];



        UIBarButtonItem *cancelButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancel:)];
        [viewController.navigationItem setLeftBarButtonItem:cancelButtonItem animated:NO];
        [cancelButtonItem release];



        NSLog(@"View 2 %@",viewController.navigationItem.rightBarButtonItem);


        break;
    }
    case 3: {

             UIBarButtonItem *editButtonItem;

             if ([viewController isKindOfClass:[ABPersonViewController class]]) {    

                    editButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(editPerson:)];
                    self.personView  = (ABPersonViewController*) viewController;
                    self.personView.allowsEditing = YES;
                    self.personView.personViewDelegate = self;
                    [viewController.navigationItem setRightBarButtonItem:editButtonItem animated:NO];
                    [editButtonItem release];

            } else {
         // ABPersonNewViewController
        //No need to add codes here
            }  

           break;
    }

    default: {




        break;
    }

}

它在 iOs 3.x 和 iOs 5.x 中运行良好,但在 iOS 4.x 中,当联系人列表出现时,导航栏中总是有取消按钮,但如果我选择一个联系人,那么我会返回第一个视图控制器添加按钮将出现。

如何仅在 iOS 4.x 中解释这种奇怪的行为?

4

2 回答 2

1

我找到了解决方案:

-(void)viewDidAppear:(BOOL)animated {


NSLog(@"Contacts view did appear");

[super viewDidLoad];
picker = [[ABPeoplePickerNavigationController alloc]init];
[picker setDelegate:self];
[picker setAllowsCancel:NO];

self.picker.navigationBar.tintColor = [UIColor blackColor];
[self presentModalViewController:picker animated:YES];

}

因此,如果您想删除 iOs 4.x 中的取消按钮,您必须添加以下行: [picker setAllowsCancel:NO]; 我收到了来自编译器的警告,但现在 iOS 4.x 中删除了取消按钮

于 2012-02-03T10:38:49.547 回答
0
[picker setAllowsCancel:NO];

//picker 是 ABPeoplePickerNavigationController 的一个对象。

于 2012-05-15T22:00:07.053 回答