【问题标题】:prepopulated fields in new contact form in iPhone and done button will save contactiPhone中新联系人表单中的预填充字段和完成按钮将保存联系人
【发布时间】:2013-02-16 13:59:05
【问题描述】:

我在以编程方式在 iPhone 的新联系人表单中添加字段时遇到困难。

我可以通过查看示例“快速联系”来打开新的联系表单,但是我不知道如何在字段中添加详细信息,这样用户就不必手动添加它们并且用户可以选择仅限完成或取消,但他/她可以更改字段中的字段详细信息。

我正在使用下面的代码来带来新的联系表格。

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

【问题讨论】:

    标签: iphone ios abaddressbook


    【解决方案1】:

    我通过下面的代码做到了。

    ABRecordRef person = ABPersonCreate();
    CFErrorRef  error = NULL;
    
    // firstname
    ABRecordSetValue(person, kABPersonFirstNameProperty, @"Don Juan", NULL);
    
    // email
    ABMutableMultiValueRef email = ABMultiValueCreateMutable(kABMultiStringPropertyType);
    ABMultiValueAddValueAndLabel(email, @"expert.in@computer.com", 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];
    

    【讨论】:

      猜你喜欢
      • 2012-08-12
      • 2017-12-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多