2013-02-16 33 views
1

我有困難在iPhone的新聯繫人窗體中以編程方式添加字段。預先填充的字段在iPhone中的新聯繫人表單和完成按鈕將保存聯繫人

我可以通過查看示例「快速聯繫」打開新的聯繫表單,但是我不知道如何在字段中添加詳細信息,以便用戶不必手動添加它們,用戶可以選擇完成或但只能取消他/她可以更改字段中的字段詳細信息。

我正在使用下面的代碼來帶來新的聯繫表單。

ABNewPersonViewController *picker = [[ABNewPersonViewController alloc] init]; 
picker.newPersonViewDelegate = self; 
UINavigationController *navigation = [[UINavigationController alloc] initWithRootViewController:picker]; 
[self presentModalViewController:navigation animated:YES]; 
[picker release]; 
[navigation release]; 

請幫忙。

回答

2

我通過下面的代碼。

ABRecordRef person = ABPersonCreate(); 
CFErrorRef error = NULL; 

// firstname 
ABRecordSetValue(person, kABPersonFirstNameProperty, @"Don Juan", NULL); 

// email 
ABMutableMultiValueRef email = ABMultiValueCreateMutable(kABMultiStringPropertyType); 
ABMultiValueAddValueAndLabel(email, @"[email protected]", CFSTR("email"), NULL); 
ABRecordSetValue(person, kABPersonEmailProperty, email, &error); 
CFRelease(email); 

// Start of Address 
ABMutableMultiValueRef address = ABMultiValueCreateMutable(kABMultiDictionaryPropertyType); 
NSMutableDictionary *addressDict = [[NSMutableDictionary alloc] init]; 
[addressDict setObject:@"The awesome road numba 1" forKey:(NSString *)kABPersonAddressStreetKey]; 
[addressDict setObject:@"0568" forKey:(NSString *)kABPersonAddressZIPKey]; 
[addressDict setObject:@"Oslo" forKey:(NSString *)kABPersonAddressCityKey]; 
ABMultiValueAddValueAndLabel(address, addressDict, kABWorkLabel, NULL); 
ABRecordSetValue(person, kABPersonAddressProperty, address, &error); 
[addressDict release]; 
CFRelease(address); 
ABNewPersonViewController *picker = [[ABNewPersonViewController alloc] init]; 
picker.displayedPerson = person; 
picker.newPersonViewDelegate = self; 

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

[picker release]; 
[navigation release]; 
相關問題