我正在尝试在 UITabBarController 中显示 iPhone 通讯录中的联系人。我到目前为止:
- (void)contacts
{
ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
// place the delegate of the picker to the controller
picker.peoplePickerDelegate = self;
CGRect newFrame = self.tabBarController.view.frame;
newFrame.size.height = newFrame.size.height - 49;
picker.view.frame = newFrame;
[picker setAccessibilityViewIsModal:YES];
// showing the picker
[self.tabBarController presentModalViewController:picker animated:NO];
}
调用:
-(void)viewWillAppear:(BOOL)animated
{
[self contacts];
}
结果我得到这个:
- 我看不到标签
- 我的标签样式是黑色,但选择器是蓝色。
- 有取消按钮。
如何使选项卡可见、将样式设为黑色并去掉取消按钮?
提前谢谢您。
编辑:
更改方法后:
-(void)contacts
{
ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
picker.peoplePickerDelegate = self;
picker.navigationBar.tintColor=[UIColor blackColor];
// Display only a person's phone, email, and birthdate
NSArray *displayedItems = [NSArray arrayWithObjects:[NSNumber numberWithInt:kABPersonPhoneProperty], nil];
picker.displayedProperties = displayedItems;
// Show the picker
picker.navigationBar.hidden=YES;
CGRect newFrame = picker.view.frame;
newFrame.size.height = newFrame.size.height - 49;
picker.view.frame = newFrame;
[self.tabBarController.view addSubview:picker.view];
}
我得到了这个结果:
是的,联系人位于选项卡内,但现在出现问题:
- 当我触摸带有联系人的 tableView 时,联系人根本消失了。
- 当我切换标签页时,联系人 View 不会消失,我可以在所有标签页中看到它。
- UISearchbar 的一半保持隐藏状态。
邪恶现在在哪里?
最佳答案
您正在 tabBarController 之上呈现 View Controller ,这就是隐藏 tabBar 的原因。尝试这样的事情:
UIViewController *controller = [tabBarController.viewControllers objectAtIndex:0]; // Let's assume this is the desired view controller that should display the ABPeoplePickerNavigationController
[controller presentModalViewController:picker animated:NO];
请记住,在选项卡栏 Controller 下呈现 UIViewController(子类)可能会导致一些非常奇怪的用户体验。此外,您必须为 ABPeoplePickerNavigationController 设置一个表格 View 底部插入(与 tabBar 相同的高度,通常为 49px),以便查看表格的最后一个条目。
ABPeoplePickerNavigationController 有一个 navigationBar 属性,您可以将其色调更改为(例如)黑色:
ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
picker.navigationBar.tintColor = [UIColor blackColor];
我怀疑您是否能够删除取消按钮而不会在应用审批过程中被拒绝。此外,ABPeoplePickerNavigationController 中没有取消按钮的属性,因此您必须从例如扫描导航栏 subview 。
关于iPhone:ABPeoplePickerNavigationController 将无法在 UITabBarController 中正确显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10342624/