iPhone地址簿-如何通过我的应用程序使用应用程序创建新记录 [英] iPhone AddressBook - how to create a new record with app from my App

查看:66
本文介绍了iPhone地址簿-如何通过我的应用程序使用应用程序创建新记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过我的App创建一个新的Person记录.我有名字,电子邮件和电话号码. 如何将它们传递给newPerson的模式视图? 我正在关注Apple的文档,但我遇到了麻烦. 我正在使用ABNewPersonViewController.那是对的吗?如何填充模式视图中的字段?

I'm trying to create a new record of Person thru my App. I have the name, email and phone nr. How can i pass them to the modal view of newPerson? I'm following Apple's docs, but i'm stuck. I'm using a ABNewPersonViewController. Is that correct? How do I fill the fields in the modal view?

谢谢

RL

推荐答案

如果要在ABNewPersonViewController中显示某些内容,则必须为要预填充的属性创建并设置ABRecordRef,然后设置displayPerson ABNewPersonViewController上的属性.因此,一个简单的示例可能是:

If you want to display something in the ABNewPersonViewController, you have to create and set up an ABRecordRef for the properties you want to pre-fill and then set the displayedPerson property on ABNewPersonViewController. So a simple example may be:

- (void)createNewPerson
{
  // Create the pre-filled properties
  ABRecordRef newPerson = ABPersonCreate();
  CFErrorRef error = NULL;
  ABRecordSetValue(newPerson, kABPersonFirstNameProperty, CFSTR("John"), &error);
  ABRecordSetValue(newPerson, kABPersonLastNameProperty, CFSTR("Smith"), &error);
  NSAssert( !error, @"Something bad happened here." );

  // Create and set-up the new person view controller
  ABNewPersonViewController* newPersonViewController = [[ABNewPersonViewController alloc] initWithNibName:nil bundle:nil];
  [newPersonViewController setDisplayedPerson:newPerson];
  [newPersonViewController setNewPersonViewDelegate:self];

  // Wrap in a nav controller and display
  UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:newPersonViewController];
  [self presentModalViewController:navController animated:YES];

  // Clean up everything
  [navController release];
  [newPersonViewController release];
  CFRelease(newPerson);
}

这篇关于iPhone地址簿-如何通过我的应用程序使用应用程序创建新记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆