2

我想从故事板中的按钮继续播放到ABPersonViewController。 但是,如果我这样做,屏幕是完全黑色的。Segue to ABPersonViewController in Storyboard

如果我使用一个IBAction的按钮,使用下面的代码它的工作原理:

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; 

} 
+0

您是否为触发的特定按钮添加了动作?你如何呈现视图控制器? – Meera

+0

[Display ABPeoplePickerNavigationController using storyboard segue]的可能重复(http://stackoverflow.com/questions/8953080/display-abpeoplepickernavigationcontroller-using-storyboard-segue) – Marco

回答

-1

您没有设置displayedPerson属性...

@property(nonatomic, readwrite) ABRecordRef displayedPerson 
+0

这不是问题所在。如果你不设置它,你只需要一个空的ABPersonViewController。但是与故事板,我只是得到一个黑屏。 – bllubbor

-1

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

0

由于您使用的故事板,你应该应该命名您正在使用的SEGUE,然后这在IBAction为:

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

这种方式,你甚至都不需要手动调用分配/初始化。然后在你的prepareForSegue你可以设置任何属性:

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

如果这不是你要找的请让我知道。

相关问题