2

I am trying to segue to a ABPersonViewController from a button in the Storyboard. But if I do that the screen is completely black.

If I use a IBAction for the button and use the following code it works:

ABPersonViewController *person = [[ABPersonViewController alloc]init];
    [self.navigationController pushViewController:person animated:YES];

Why is that? am I doing wrong?

EDIT: I found a work around but I don't think this is a proper way to do it. I subclassed ABPersonViewController and overrode the initWithCoder method with the following:

-(id)initWithCoder:(NSCoder *)aDecoder{

    self = [self initWithNibName:nil bundle:nil];
    return self;

}
jww
  • 97,681
  • 90
  • 411
  • 885
BObereder
  • 1,046
  • 1
  • 13
  • 29
  • Did you add the action from triggered segues for the particular button? How are you presenting the view controller? – Meera Jan 28 '13 at 06:35
  • possible duplicate of [Display ABPeoplePickerNavigationController using storyboard segue](http://stackoverflow.com/questions/8953080/display-abpeoplepickernavigationcontroller-using-storyboard-segue) – Marco Feb 13 '14 at 22:34

3 Answers3

1

Since you are using storyboards you should should name the segue you are using and then this in your IBAction:

[self performSegueWithIdentifier:@"abPersonViewControllerSegue" sender:self];

This way you do not even need to manually call alloc/init. Then in your prepareForSegue you could set any attributes:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"abPersonViewControllerSegue"]) 
    {
        [segue.destinationViewController setAttribute:@"whatever you want"];
        ...      
    }
}

If this is not what you are looking for please let me know.

Firo
  • 15,448
  • 3
  • 54
  • 74
-1

You don't set the displayedPerson property ...

@property(nonatomic, readwrite) ABRecordRef displayedPerson
Cristian Bica
  • 4,067
  • 27
  • 28
  • this is not the problem. If you don't set it you just get an empty ABPersonViewController. But with Storyboard I just get a black screen. – BObereder Dec 24 '12 at 09:24
-1

Since you are using Storyboard, why do you still call [[ABPersonViewController alloc]init]?The Storyboard will handle the creation and pushing of the ABPersonViewController(if you specified Push action for the segue). As long as you control dragged from the Button to the ABPersonViewController in story board, you do not need to write a single line of code. If you control dragged from the view controller that contains the button, then you should be calling performSegue to trigger the segue(you need to set the identifier for the segue in this case) that adds the ABPersonViewController to the navigation controller.

Ray
  • 16,025
  • 5
  • 31
  • 51