删除 ABPeoplePickerNavigationController 中的取消按钮。 iOs 4.x 中的奇怪行为

发布于 2025-01-02 06:17:11 字数 2208 浏览 1 评论 0原文

我想删除 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 中的这种奇怪行为?

I would like to remove the cancel button in the navigation bar of ABPeoplePickerNavigationController because I want to have an add button.
I customized the navigation controller delegate in this way:

- (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;
    }

}

It works fine in iOs 3.x and iOs 5.x, but in iOS 4.x I always have the cancel button in the navigation bar when the contacts list appears but if I select a contact then I go back to the first view controller the add button will appear.

How can explain this strange behavior only in iOS 4.x ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

赠佳期 2025-01-09 06:17:11

我找到了解决方案:

-(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 中的取消按钮,你必须添加这一行:
[选择器设置允许取消:否];
我收到了来自编译器的警告,但现在取消按钮在 iOS 4.x 中被删除了

I found the solution:

-(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];

}

So if you want to remove the cancel button in iOs 4.x you have to add this line:
[picker setAllowsCancel:NO];
I received a warning from the compiler, but now the cancel button is removed in iOS 4.x

寻找我们的幸福 2025-01-09 06:17:11
[picker setAllowsCancel:NO];

//picker是ABPeoplePickerNavigationController的一个对象。

[picker setAllowsCancel:NO];

//picker is an object of ABPeoplePickerNavigationController.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文