取消和完成按钮在新的联系人视图中不起作用

时间:2010-11-19 04:39:46

标签: iphone objective-c ios

我正在尝试在我的应用中集成新的联系人控件。这是我的代码:

- (BOOL) personViewController:(ABPersonViewController*)personView shouldPerformDefaultActionForPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifierForValue 
{ 
    return YES;
}

-(IBAction)addcontact:(id)sender{

    ABNewPersonViewController *picker = [[ABNewPersonViewController alloc] init];

    UINavigationController *navigation = [[UINavigationController alloc] initWithRootViewController:picker];
    [self presentModalViewController:navigation animated:YES];

    [picker release];
    [navigation release];

}

会弹出新的联系人视图,但是当我点击取消完成按钮时,没有任何反应。 谁能帮我?

提前致谢!

2 个答案:

答案 0 :(得分:4)

//Make sure your VC is an <ABNewPersonViewControllerDelegate>
-(void) newPersonViewController:(ABNewPersonViewController *)newPersonView 
    didCompleteWithNewPerson:(ABRecordRef)person {

if (person != nil)  //nil = Cancel button clicked
{
  //do something  
}

//iOS6
[self dismissViewControllerAnimated:YES completion:nil];
}

答案 1 :(得分:1)

您需要添加在点击取消或完成按钮时应调用的方法,并且该方法应调用[self.navigationController dismissModalViewController