简体   繁体   中英

Presenting a view in a ViewController that is in a UITabBarController

I'm still learning iOS development, so I apologize if my title is not accurate terminology :(

I have a TabBarController and one of the views associated with it has its own ViewController class. I'm trying to display the iOS contacts when this scene loads up. I want the contacts UI to be contained within the tab bar bounds. Right now, it pops up and replaced the the whole scene, so I lose my tab bar at the bottom. I would like to keep it.

Any suggestions?

Here is my current code for this class

#import "DeviceContactsViewController.h"

@interface DeviceContactsViewController ()

@end

@implementation DeviceContactsViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization

    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)viewDidAppear:(BOOL)animated
{
    ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
    picker.peoplePickerDelegate = self;

   [self presentViewController:picker animated:YES completion:nil];
}

#pragma mark - Contacts

- (void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker
{
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (BOOL)peoplePickerNavigationController: (ABPeoplePickerNavigationController *)peoplePicker
      shouldContinueAfterSelectingPerson:(ABRecordRef)person {
    [self dismissViewControllerAnimated:YES completion:nil];

    return NO;
}


- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker
      shouldContinueAfterSelectingPerson:(ABRecordRef)person
                                property:(ABPropertyID)property
                              identifier:(ABMultiValueIdentifier)identifier
{
    return NO;
}

@end

场景

This Happened because you are saying [self presentViewController:picker animated:YES completion:nil]; , that line will present your view on top of everything, whether you have a tabbar or a navigation bar.

The default behaviour of the Tabbar is to link each one of the tabs to a separate ViewController, so each tabbaritem should be linked to a ViewController from your StoryBoard , you have nothing to do with presenting the ViewController, it happens by default, all the transitions between view controllers happen by default.

Check out this tutorial, you'll see how they're linked together: Ray Wenderlich, StoryBoards linking

Hope it helps :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM