ABPersonViewController 不保存更改
在我正在编写的应用程序中,我允许用户将联系人与事件关联起来。他们可以使用地址簿 UI 框架添加新的或现有的联系人。
一旦联系人关联起来,它们就会显示出来,用户可以单击它们来调出 ABPersonViewController
。编辑似乎可以进行,但是当人物视图关闭时,更改不会保存。
以下是相关代码:
ABPersonViewController *personController = [[ABPersonViewController alloc] init];
personController.personViewDelegate = self;
personController.allowsEditing = YES;
personController.displayedPerson
[self.navigationController pushViewController:personController animated:YES];
[personController release];
编辑联系人并关闭人员视图后,如果我再次单击该联系人,则不会出现任何更改的信息。
我尝试创建一个 ABAddressBookRef 属性,并使用将其分配给控制器
personController.addressBook = ab;
,然后保存地址簿,但这也不起作用。
编辑:
我已经实现了
。它只有一种方法,如果我没记错的话,未能实现该方法将导致 ABPersonViewController 根本无法工作。
这是我的完整实现:
- (BOOL)personViewController:(ABPersonViewController *)personViewController shouldPerformDefaultActionForPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier {
return YES;
}
据我所知,这仅意味着控制器将正常运行。
编辑2:
好的,所以我刚刚意识到控制器没有显示除所选人员的姓名之外的任何信息。我认为这意味着我的 ABRecordRefs 在某种程度上是不正确的。我会调查。
我将联系人存储为包含记录 ID 的 NSNumber 数组。这是我的代码(其中 contactIDs 是记录 ID 数组,ab 是一个 ABAddressBookRef
):
NSMutableArray *contactArray = [NSMutableArray array];
for (NSNumber *contactNumber in contactIDs) {
NSInteger contactID = [contactNumber intValue];
[contactArray addObject:ABAddressBookGetPersonWithRecordID(ab, contactID)];
}
这似乎有效,因为当我选择联系人时会加载正确的名称。但是,没有显示其他信息。
In the app I am writing, I allow users to associate contacts with events. They can add new or existing contacts using the Address Book UI Framework.
Once the contacts are associated, they are displayed, and the user can click them to bring up an ABPersonViewController
. Editing appears to work, but when the person view is closed, the changes are not saved.
Here is the relevant code:
ABPersonViewController *personController = [[ABPersonViewController alloc] init];
personController.personViewDelegate = self;
personController.allowsEditing = YES;
personController.displayedPerson
[self.navigationController pushViewController:personController animated:YES];
[personController release];
After editing a contact and closing the person view, if I click on the contact again, none of the altered information is present.
I tried creating an ABAddressBookRef
property, and assigning it to the controller using
personController.addressBook = ab;
And then saving the address book afterwards, but that did not work either.
EDIT:
I already implement the <ABPersonViewControllerDelegate>
. It only has one method, and if I recall correctly, failure to implement that would prevent the ABPersonViewController from working at all.
Here is my full implementation:
- (BOOL)personViewController:(ABPersonViewController *)personViewController shouldPerformDefaultActionForPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier {
return YES;
}
As far as I am aware, this just means that the controller will behave normally.
EDIT 2:
OK, so I just realized that the controller is not displaying any information about the selected person except their name. I assume this means that my ABRecordRefs are incorrect in some way. I will investigate.
I store contacts as an array of NSNumbers containing the record IDs. Here is my code (where contactIDs is the array of record IDs, and ab is an ABAddressBookRef
):
NSMutableArray *contactArray = [NSMutableArray array];
for (NSNumber *contactNumber in contactIDs) {
NSInteger contactID = [contactNumber intValue];
[contactArray addObject:ABAddressBookGetPersonWithRecordID(ab, contactID)];
}
This seems like it is working, because the correct name is loaded when I select a contact. However, no other information is displayed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我成功了。问题是我使用了两个不同的 ABAddressBookRef。
我使用一个 ABAddressBookRef 创建了一个 ABRecordRefs 数组(如我编辑的问题中所示),但是当我从数组中读取 ABRecordRef 时,我一直在使用的 ABAddressBookRef 已经被释放了。
我使 ABAddressBookRef 的实例在我的类实例的整个生命周期中持续存在,并且它有效。
I got it working. The problem was that I was using two different ABAddressBookRefs.
I created an array of ABRecordRefs (as seen in my edited question) using one ABAddressBookRef, but when I read an ABRecordRef from the array, the ABAddressBookRef I had been using had already been released.
I made an instance of ABAddressBookRef persist throughout the full life cycle of my class instance, and it worked.
您需要设置所有地址簿委托方法来解决此问题。
转到此链接
You need to set all addressbook delegate method to solve this issue.
Go to this Link
您是如何创建地址簿的?您使用过
ABAddressBookCreate()
吗?此外,您应该确保正确实现
ABPersonViewControllerDelegate
。请查看此示例 http://developer.apple.com /library/ios/#samplecode/QuickContacts/Introduction/Intro.html
我相信它包含您需要的一切!
更新您应该尝试ABAddressBookSave方法!
干杯,
唐
How did you create the AddressBook? Did you use
ABAddressBookCreate()
?Moreover, you should make sure that you implement the
ABPersonViewControllerDelegate
correctly.Please check out this example http://developer.apple.com/library/ios/#samplecode/QuickContacts/Introduction/Intro.html
I believe that it consists all you need!
Update you should try out ABAddressBookSave method!
Cheers,
Thang