How do I set an ABPeoplePickerNavigationController's prompt?

狂风中的少年 提交于 2019-12-10 20:31:19

问题


This is the code I'm using to call the people picker, but the prompt label text doesn't change:

ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
picker.peoplePickerDelegate = self;
picker.displayedProperties = [NSArray arrayWithObjects: [NSNumber numberWithInt:kABPersonEmailProperty], nil];  

picker.navigationItem.prompt = @"Choose a contact to...";

[self presentModalViewController:picker animated:YES];

回答1:


You can change the title with:

picker.navigationBar.topItem.title = @"iPhone Contacts";

And you can change the prompt with:

picker.navigationBar.topItem.prompt = @"iPhone Contacts";



回答2:


There is a key piece of information missing in the other answers, and not quite obvious. You need to set the prompt after the line:

[self presentModalViewController:picker animated:YES];

So, if you do it like this, it works:

[self presentModalViewController:picker animated:YES];
picker.navigationBar.topItem.prompt = @"Choose a contact to...";



回答3:


I've just stumbled upon a way to do this. However, I'm not sure it's the best way. Just replace in the code above the line

picker.navigationItem.prompt = @"Choose a contact to...";

With

picker.navigationBar.topItem.prompt = @"Choose a contact to...";



回答4:


If you're sub-classing the ABPeoplePickerNavigationController you need to set this once the view controller is pushed. This is in effect what achieving the same thing that Johan suggested, but from within the class.

In the ABPeoplePickerNavigationController implement the following delegate method like so:

-(void)navigationController:(UINavigationController *)navigationController 
     willShowViewController:(UIViewController *)viewController 
                   animated:(BOOL)animated
{
    [[[self navigationBar] topItem] setPrompt:@"test"];
}


来源:https://stackoverflow.com/questions/2438852/how-do-i-set-an-abpeoplepickernavigationcontrollers-prompt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!