2012-04-18 44 views
2

如何關閉ABPersonViewController?這裏是我的代碼無法關閉iPhone中的ABPersonViewController

#pragma mark - Edit Record Method 

-(void)btnEditContactTapped:(id)sender { 

    // Fetch the address book 
    ABAddressBookRef addressBook = ABAddressBookCreate(); 

    ABRecordID recID = ABRecordGetRecordID(record); 

    ABRecordRef record1 = ABAddressBookGetPersonWithRecordID(addressBook,recID); 

    ABPersonViewController *personViewController = [[ABPersonViewController alloc]init]; 
    // set delegate 
    personViewController.personViewDelegate = self; 

    // Allow editing info 
    personViewController.allowsEditing = YES; 

    // Display contact info of selected person 
    personViewController.displayedPerson = record1; 

    // Person view controllers must be used with a navigation controller in order to function properly. 
    UINavigationController *nc = [[UINavigationController alloc] 
            initWithRootViewController:personViewController]; 
    [self presentModalViewController:nc animated:YES]; 
    [personViewController release]; 

} 

#pragma mark - ABPersonViewControllerDelegate Method 

- (BOOL)personViewController:(ABPersonViewController *)personViewController shouldPerformDefaultActionForPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifierForValue { 

    [self dismissModalViewControllerAnimated:YES]; 
    return NO; 
} 

記錄在我的ivar中聲明爲.h文件中的ABRecordRef記錄。 ABPersonViewControllerDelegate方法永遠不會被調用?出了什麼問題?任何形式的幫助表示讚賞。謝謝

+0

我有同樣的問題,你找到解決方案 – wod 2013-02-11 14:50:09

回答

0

您是否在項目的.h中實現了這些協議..?

< ABPeoplePickerNavigationControllerDelegate, 
                   ABPersonViewControllerDelegate, 
                   ABNewPersonViewControllerDelegate, 
                   ABUnknownPersonViewControllerDelegate> 
+0

不是全部。我的.h文件中只有ABPersonViewControllerDelegate。爲什麼我需要上述所有內容?另外讓我知道我需要實現哪些委託方法。謝謝。 – iOSAppDev 2012-04-18 12:12:16

+0

你不需要所有我只是提到他們所有的,因爲我不能你的完整代碼...如果你沒有得到任何警告,那麼你有所有的方法,你需要實現...其他方式來確定是去ABPersonViewControllerDelegate的定義並在「required」標題下尋找方法.. – 2012-04-18 12:15:36

+0

ABPersonViewControllerDelegate只有一個我已經實現的方法(在我的代碼中顯示)。仍然沒有工作。任何想法? – iOSAppDev 2012-04-18 12:42:15