iPhone:ABPeoplePickerNavigationController 将无法在 UITabBarController 中正确显示

标签 iphone objective-c ios uitabbarcontroller

我正在尝试在 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];
}

结果我得到这个:

enter image description here

  1. 我看不到标签
  2. 我的标签样式是黑色,但选择器是蓝色。
  3. 有取消按钮。

如何使选项卡可见、将样式设为黑色并去掉取消按钮?

提前谢谢您。

编辑:

更改方法后:

-(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];

}

我得到了这个结果:

enter image description here

是的,联系人位于选项卡内,但现在出现问题:

  1. 当我触摸带有联系人的 tableView 时,联系人根本消失了。
  2. 当我切换标签页时,联系人 View 不会消失,我可以在所有标签页中看到它。
  3. 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/

相关文章:

ios - 尝试从 objects[0] 中插入 nil object in objective-c

ios - Swift:如何以编程方式向单元格添加 TextView 并调整其大小?

ios - Objective-C 中原子/非原子的证据

iphone - 下载并保存可以为空白的图像

c# - 是否可以将大的本地化字符串换成他们自己的文件?

ios - 通过在 lldb 中添加 borderColor 来调试 View

ios - 让图像沿着 x 轴跟随您的手指,但具有固定的 y 坐标

iphone - Xcode 字体大小在 iPhone 上测试时随机变化

iphone - 自定义单元格 : fatal error: unexpectedly found nil while unwrapping an Optional value

iphone - 在应用程序购买Apple ID登录警报中听“取消”按钮?