2011-05-27 53 views
0

我正在開發一個應用程序,並且我必須打開地址簿,我已經使用ABPeoplePickerNavigationController來打開地址簿,並在其中存儲了所有電話號碼和電子郵件用戶,但是我並不知道如何存儲電話號碼或電子郵件的價值,假設用戶點擊電子郵件字段時,電子郵件地址存儲在某個變量中,並且如果點擊電話號碼存儲在另一個變量中。如何選擇iPhone中地址簿中的特定字段

回答

2

你好請找到下面的代碼......

你可以從你的iPhone通訊錄獲取名字,姓氏,人的形象和移動電話號碼

Add按鈕將你的ViewController並添加該代碼到你的按鈕點擊事件。

-(IBAction)btnGetNameClicked:(id)sender { 
     // creating the picker 
    ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init]; 
    // place the delegate of the picker to the controll 
    picker.peoplePickerDelegate = self; 

    // showing the picker 
    [self presentModalViewController:picker animated:YES]; 
    // releasing 
    [picker release]; 
} 

-(BOOL)peoplePickerNavigationController: (ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person { 

    // setting the first name 
    lblFirstName.text = (NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty); 

    // setting the last name 
    lblLastName.text = (NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty); 

    ABMultiValueRef multi = ABRecordCopyValue(person, kABPersonPhoneProperty); 
    lblNumber.text = (NSString*)ABMultiValueCopyValueAtIndex(multi, 0); 
    if(ABPersonHasImageData(person)){ 
     imgPerson.image = [UIImage imageWithData:(NSData *)ABPersonCopyImageData(person)]; 
    } else { 
     imgPerson.image = [UIImage imageNamed:@"NotAvailable.png"]; 
    } 

    // remove the controller 
    [self dismissModalViewControllerAnimated:YES]; 

    return NO; 
} 
+0

感謝張建東但是我對給定函數的工作 - (BOOL)peoplePickerNavigationController:(的ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)個人財產:(ABPropertyID)屬性標識符:(ABMultiValueIdentifier)標識符 而選擇將其命名爲顯示的名稱和電子郵件屬性從那裏選擇任何一個屬性應該存儲的值 – user748001 2011-05-27 13:19:11

+0

如果您發現滿意的答案,然後upvote和標記爲正確.... – 2011-05-27 13:22:44

相關問題