ABPeoplePickerNavigationController - remove the cancel button without using private methods / properties?

I use ABPeoplePickerNavigationController, a subclass of UINavigationController, and in the context that I use, the default navigation button for the right side, "Cancel", makes no sense. I can’t find a way to disable or hide it, and any method used should be public and accessible to the store. Getting rid of the navigation bar completely (picker.navigationBarHidden = YES;) may be an option, except that after returning to the contact list, the navigation bar appears again. Subclassing ABPeoplePickerNavigationController and intercepting viewWillAppear to try and cancel the cancel button does not work. [picker setAllowsCancel: NO]; It works, but is not documented, so I expect it to never pass approval.

+5
source share
10 answers

There is no answer to this question - write a new person if you cannot live with cancellation.

0
source

this

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
  UIView *custom = [[UIView alloc] initWithFrame:CGRectMake(0.0f,0.0f,0.0f,0.0f)]; 
  UIBarButtonItem *btn = [[UIBarButtonItem alloc] initWithCustomView:custom]; 
  //UIBarButtonItem *btn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addAction)]; 
  [viewController.navigationItem setRightBarButtonItem:btn animated:NO]; 
  [btn release]; 
  [custom release]; 
}

works great!

+4
source

navigationController: willShowViewController: : , , , , . , , :

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

    // Here we want to remove the 'Cancel' button, but only if we're showing
    // either of the ABPeoplePickerNavigationController top two controllers
    if ([navigationController.viewControllers indexOfObject:viewController] <= 1) {

        viewController.navigationItem.rightBarButtonItem = nil;
    }
}

, , . , viewController .

+2

, . ...

0

PeoplePickerController. .

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
 UIView *pCustomView = [[UIView alloc] initWithFrame:CGRectMake(0,0,0,0)];
 UIBarButtonItem *pBtn = [[UIBarButtonItem alloc] initWithCustomView:pCustomView];
 [viewController.navigationItem setRightBarButtonItem:pBtn animated:NO];
 [pBtn release];
 [pCustomView release];
}
0

, , Uby , subviews , , isKindOfClass: [UIBarButtonItem class], title. navigationBar 'Item'.

0

- ( peoplePickerDelegate, ) , :

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
UIView *custom = [[UIView alloc] initWithFrame:CGRectMake(0,0,0,0)];
UIBarButtonItem *btn = [[UIBarButtonItem alloc] initWithCustomView:custom];
[viewController.navigationItem setRightBarButtonItem:btn animated:NO];
[btn release];
[custom release];
} 
0

, iOS 4 . , , .

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

. :

- (void)applicationDidEnterBackground:(UIApplication *)application {
    id topView = pickerControllerDelegate.peoplePicker.topViewController;
    topView.navigationItem.rightBarButtonItem = nil;
}

.

0

EDIT: . . , .

API ABPeoplePickerNavigationController , . .

, , ..., .

(: ):

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [self killCancelButton];
}

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
    [super pushViewController:viewController animated:animated];
    [self killCancelButton];
}

- (UIViewController*)popViewControllerAnimated:(BOOL)animated {
    UIViewController *result = [super popViewControllerAnimated:animated];
    [self killCancelButton];
    return result;
}

- (void)killCancelButton {
    for (NSUInteger itemIdx = 0; itemIdx < self.navigationBar.items.count; itemIdx++) {
        UINavigationItem *item = [self.navigationBar.items objectAtIndex:itemIdx];
        item.rightBarButtonItems = [[NSArray alloc] init];
    }
}
0

russel b viewdidapper

:

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    UINavigationItem *item = (UINavigationItem *)[self.navigationBar.items lastObject];
    item.rightBarButtonItems = [[NSArray alloc] init];

    item.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addPerson)];
}
0

All Articles