2

我正在尝试ABPersonViewController从情节提要中的按钮转到 a 。但如果我这样做,屏幕就完全黑了。

如果我使用 aIBAction作为按钮并使用以下代码,它可以工作:

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

这是为什么?我做错了吗?

编辑:我找到了解决方法,但我认为这不是正确的方法。我ABPersonViewControlle将 r 子类化并使用以下内容覆盖了该initWithCoder方法:

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

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

}
4

3 回答 3

1

由于您使用的是故事板,您应该命名您正在使用的 segue,然后在您的 IBAction 中命名:

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

这样你甚至不需要手动调用 alloc/init。然后在您的 prepareForSegue 中,您可以设置任何属性:

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

如果这不是您要找的东西,请告诉我。

于 2013-01-31T18:56:07.400 回答
-1

您没有设置 displayPerson 属性...

@property(nonatomic, readwrite) ABRecordRef displayedPerson
于 2012-12-23T00:02:37.327 回答
-1

既然你在使用 Storyboard,为什么还要调用 [[ABPersonViewController alloc]init]?Storyboard 会处理 ABPersonViewController 的创建和推送(如果你为 segue 指定了 Push 动作)。只要您将控件从 Button 拖到 Storyboard 中的 ABPersonViewController 中,就不需要编写一行代码。如果您控制从包含按钮的视图控制器拖动,那么您应该调用 performSegue 来触发将 ABPersonViewController 添加到导航控制器的 segue(在这种情况下您需要设置 segue 的标识符)。

于 2013-01-30T23:13:50.207 回答