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.
views:
721answers:
7I have the same problem. I tried nearly everythint at the moment. Without success
There is no answer to this - write a new person picker if you can't live with the cancel.
You can achieve that result browsing through the picker subviews. Just a little boring...
Set delegate to PeoplePickerController controller. In the delegate class, have this delegate method.
- (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]; }
I haven't tried it yet, but I think Uby is saying to iterate through the subviews of the picker until you find one that is isKindOfClass:[UIBarButtonItem class] and then you can change it's title property. It might also be in the navigationBar's 'Item' array.
Be sure to set the delegate for picker object (not the peoplePickerDelegate, just the delegate) to the class that implement the following method:
- (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]; }
It works fine but in iOS 4 there is one more thing. When I switch back to my app using Fast App Switching feature Cancel Button appears again. The
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
isn't called then so I made this:
- (void)applicationDidEnterBackground:(UIApplication *)application {
pickerControllerDelegate.peoplePicker.topViewController.navigationItem.rightBarButtonItem=nil; }
It works pretty well.
I hope it will help.