2011-03-24 93 views
1

使用Apple的Quick Contacts示例代碼中的ABPersonViewController。ABPersonViewController完成編輯通知

ABRecordRef person = (ABRecordRef)[people objectAtIndex:0]; 
    ABPersonViewController *picker = [[[ABPersonViewController alloc] init] autorelease]; 
    picker.personViewDelegate = self; 
    picker.displayedPerson = person; 
    picker.allowsEditing = YES; 
    [self.navigationController pushViewController:picker animated:YES]; 

我需要被通知選擇器已完成編輯或已結束,所以我可以更新我的數據存儲一些緩存值的方式。

Apple的文檔推薦遠離ABPersonViewController的子類。任何建議,非常感謝!

回答

2
ABPersonViewController *personViewController = [[ABPersonViewController alloc] init]; 

     personViewController.personViewDelegate = self; 
     personViewController.displayedPerson = person; 
     personViewController.allowsEditing=YES; 
     personViewController.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Back",nil) style:UIBarButtonItemStylePlain target:self action:@selector(ReturnFromPersonView)] ; 
     [self.navigationController pushViewController:personViewController animated:YES]; 
     [personViewController release]; 

然後再編寫ReturnFromPersonView方法和委託方法

- (BOOL)personViewController:(ABPersonViewController *)personViewController shouldPerformDefaultActionForPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifierForValue 
{ 
     // you can write you code here with [self.navigationController popViewControllerAnimated:YES]; 
     return YES;  
} 

如果你不喜歡 「返回鍵」 的方法 - 你可以寫你的代碼直接到personViewController shouldPerformDefaultActionForPerson:

+0

謝謝: )我通過儘量減少核心數據中的冗餘存儲(只保留記錄ID以供參考)並在需要時檢索地址簿值來避免此問題,以保持最新的值。 – 2011-03-26 05:13:39

相關問題