在iOS8中隐藏ABPeoplePickerNavigationController上的取消按钮

时间:2015-07-16 21:05:27

标签: ios objective-c ios8

我试图隐藏ABPeoplePickerNavigationController的取消按钮。以下代码在iOS 7.1模拟器中运行时正常,正确隐藏按钮。但是,在iOS 8.4模拟器中运行时它没有任何效果。在这两种情况下,日志消息都写入调试器,因此我知道代码正在执行。

除了这段代码之外,我还尝试了继承ABPeoplePickerNavigationController(即使Apple文档不说)并在viewDidLoad方法中将按钮设置为nil,但这对iOS 8也没有影响。

谷歌搜索,有很多帖子询问如何做到这一点,大多数都有答案。但是,没有一个答案似乎在iOS 8中有效。我也尝试过以下帖子中提出的解决方案(以及其他许多方法)但没有成功。

ABPeoplePickerNavigationController - remove "Cancel" button without using private methods/properties?

有没有人找到一种方法来隐藏iOS 8中ABPeoplePickerNavigationController的取消按钮?

-(void)showPeoplePickerController
{
     ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
     picker.peoplePickerDelegate = self;
     picker.delegate = 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.displayedProperties = displayedItems;
     // Show the picker
     [self presentViewController:picker animated:YES completion:nil];
}

-(void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
     NSLog(@"Attempting to hide cancel button...");
     navigationController.topViewController.navigationItem.rightBarButtonItem  = nil;
}

0 个答案:

没有答案
相关问题