如何将自定义栏按钮项添加到AddressBookUI应用程序中的导航栏,如代替取消编辑

时间:2011-06-28 10:02:34

标签: iphone addressbook addressbookui

我无法理解为什么导航栏不会在以下代码中添加取消按钮以外的任何按钮    在Viber应用程序中完成的这种事情是可能的

 ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController     alloc] init];
picker.navigationBar.tintColor=[UIColor colorWithRed:91.0/256.0 green:72.0/256.0 blue:110.0/256.0 alpha:1.0];
//picker.navigationController.navigationBar.topItem.rightBarButtonItem = nil;
[picker.navigationBar setHidden:NO];
picker.peoplePickerDelegate = self;
// Display only a person's phone, email, and birthdate
NSArray *displayedItems = [NSArray arrayWithObjects:[NSNumber numberWithInt:kABPersonPhoneProperty], 
                           [NSNumber numberWithInt:kABPersonEmailProperty],
                           [NSNumber numberWithInt:kABPersonBirthdayProperty], nil];

//picker.navigationBarHidden=TRUE;
picker.displayedProperties = displayedItems;
//UIBarButtonItem *addbutton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(AddContact)];          
   //   picker.navigationController.navigationBar.topItem.rightBarButtonItem = addbutton;

[self presentModalViewController:picker animated:NO];
[picker release];
//[addbutton release];

任何人都可以帮忙

2 个答案:

答案 0 :(得分:3)

参考this文章,演示如何在ABPeoplePickerNavigationController

上添加自定义按钮

答案 1 :(得分:2)

我可以向您展示如何向导航栏添加自定义按钮。如果这有用,请使用此代码,

UIImage *buttonImage = [UIImage imageNamed:@"Done.png"];

    UIButton *aButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];

    [aButton setImage:buttonImage forState:UIControlStateNormal];

    aButton.frame = CGRectMake(0.0, 0.0, buttonImage.size.width, buttonImage.size.height);

    UIBarButtonItem *aBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:aButton];

    [aButtonaddTarget:selfaction:@selector(navigatehome)forControlEvents:UIControlEventTouchUpInside];

    self.navigationItem.rightBarButtonItem = aBarButtonItem;

    [aBarButtonItem release];