tags:

views:

89

answers:

2

ABPersonViewController is by default showing a "Cancel" button in the right button bar position. How would one go about hiding/clearing that item? Obligatory code sample follows:

ABPersonViewController *picker = [[[ABPersonViewController alloc] init] autorelease];
picker.personViewDelegate = self;
picker.displayedPerson = aPerson;
picker.allowsEditing = NO;

Thanks.

+1  A: 

SOLVED! Subclass ABPersonViewController, override -(void) viewDidLoad, call the super and THEN set the rightBarButtonItem to nil. Ta da!

@interface PersonViewController : ABPersonViewController
@end

@implementation PersonViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.rightBarButtonItem = nil;
}

@end
Kenny
Be sure to mark your own answer as accepted so it's easy for others to refer to your solution :)
BoltClock
+1  A: 

Much simpler:

ABPersonViewController *picker = [[[ABPersonViewController alloc] init] autorelease];
picker.personViewDelegate = self;
picker.displayedPerson = aPerson;
picker.allowsEditing = NO;
[self.navigationController pushViewController:picker animated:YES];
picker.navigationItem.rightBarButtonItem = nil; // remove "Cancel" button
[picker release];

(Simply added rightBarButtonItem = nil after pushViewController.)

Jeff
Seems to be a regression in iOS 4. My code works pre-iOS4, where I could add the rightBarButtonItem before hand, now I have to add it AFTER I call presentModalViewController on the UINavigationController that contains my ABPersonViewController.
Shazron