gnasher
gnasher

Reputation: 1513

ABPersonViewController and hiding the Cancel Button

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.

Upvotes: 1

Views: 2010

Answers (2)

Jeff
Jeff

Reputation: 2699

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.)

Upvotes: 1

gnasher
gnasher

Reputation: 1513

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

Upvotes: 4

Related Questions