我正试图从故事板中的按钮转到ABPersonViewController
。
但如果我这样做,屏幕就完全是黑色的。
如果我使用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 :(得分: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"];
...
}
}
如果这不是您想要的,请告诉我。
答案 1 :(得分:-1)
您没有设置displayedPerson属性...
@property(nonatomic, readwrite) ABRecordRef displayedPerson
答案 2 :(得分:-1)
由于您使用的是Storyboard,为什么还要调用[[ABPersonViewController alloc] init]?故事板将处理ABPersonViewController的创建和推送(如果您为segue指定了Push动作)。只要您控制从故事板中的Button拖动到ABPersonViewController,您就不需要编写一行代码。如果你控制从包含按钮的视图控制器拖动,那么你应该调用performSegue来触发segue(在这种情况下你需要设置segue的标识符),它将ABPersonViewController添加到导航控制器。