Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ABPeoplePickerNavigationController - remove "Cancel" button without using private methods/properties?

I'm using the ABPeoplePickerNavigationController, a subclass of UINavigationController, and in the context I'm using it the default nav bar button for the right side, "Cancel", makes no sense. I can't find a way to disable or hide it, and whatever method used needs to be public and store-approvable. Getting rid of the nav bar entirely (picker.navigationBarHidden = YES;) might be an option except that after popping back to the list of contacts the nav bar reappears. Subclassing ABPeoplePickerNavigationController and intercepting viewWillAppear to try and nil the cancel button did not work. [picker setAllowsCancel:NO]; DOES work but is undocumented so I expect would never pass approval.

like image 341
Adam Eberbach Avatar asked Oct 23 '09 05:10

Adam Eberbach


1 Answers

this one

- (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 perfect!

like image 93
user454083 Avatar answered Sep 27 '22 00:09

user454083