NCFUSN
NCFUSN

Reputation: 1644

iPhone: ABPeoplePickerNavigationController won't show up properly in UITabBarController

I am trying to show up contacts from iPhone contacts book in UITabBarController. I came so far:

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

Calling:

-(void)viewWillAppear:(BOOL)animated
{
   [self contacts];
}

As the result I am getting this:

enter image description here

  1. I can't see the tabs
  2. My tabs style is black, but the picker is blue.
  3. There's the cancel button.

How to make tabs visible, make style black and get rid of cancel button?

Thank you in advance.

EDIT:

After changing the method:

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

}

I've got this result:

enter image description here

Yes the contacts are sitting inside the tab, but now have the problems:

  1. When I touch the the tableView with contacts, the contacts are disappearing at all.
  2. When I switch the tabs, the contacts view doesn't go away and I can see it in all the tabs.
  3. The half of UISearchbar stays hidden.

Where's the evil now?

Upvotes: 2

Views: 2371

Answers (2)

Ian
Ian

Reputation: 3836

I'm hoping you figured this out by now, but it's because a modal view controller is added to the top of the active window. That's why it goes over the top of your tab bar. UIViewController also has a method presentViewController:animated:completion: that will probably work better for you. You have some animation options if you specify the type for the animation using the modalTransitionStyle property. Good luck (if it's even still a question).

Upvotes: 1

Markus
Markus

Reputation: 585

You are presenting the view controller on top of the tabBarController, that is why the tabBar is hidden. Try something like:

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

Keep in mind, presenting a UIViewController (subclass) underneath a tabbar controller might result in some really strange user experience. Furthermore, you will have to set a table view bottom inset (same height as the tabBar, which is normally 49px) to the ABPeoplePickerNavigationController in order to view the very last entry of the table.

ABPeoplePickerNavigationController has a navigationBar property, you can change it's tint color to (e.g.) black:

ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
picker.navigationBar.tintColor = [UIColor blackColor];

I doubt you will be able to remove the cancel button without being rejected at the app approval process. Furthermore, there is no property of the cancel button within the ABPeoplePickerNavigationController, so you will have to get the reference from e.g. scan through the navigationBar subviews.

Upvotes: 2

Related Questions