ios - 显示 ABPersonViewController 的这段代码有什么问题?

标签 ios objective-c

-(void) vDisplayPerson:(ABRecordRef)person
{
    ABPersonViewController *picker = [[ABPersonViewController alloc] init] ;
    picker.personViewDelegate = self;
    picker.displayedPerson = person;
    picker.displayedProperties=@[@(kABPersonPhoneProperty),@(kABPersonEmailProperty),@(kABPersonBirthdayProperty),@(kABPersonOrganizationProperty),@(kABPersonJobTitleProperty),@(kABPersonDepartmentProperty),@(kABPersonNoteProperty),@(kABPersonCreationDateProperty)];
    // Allow users to edit the person’s information
    picker.allowsEditing = YES;
    picker.allowsActions=YES;
    //[picker setValue:[NSNumber numberWithBool:YES] forKey:@"allowsDeletion"];
    [self.navigationController pushViewController:picker animated:YES];

}

在 [self.navigationController PushViewController:picker 动画:YES]之后;

我得到

2013-10-08 09:29:37.499 Recent Contact[5804:a0b] *** Assertion failure in +[CNContact propertyForPropertyID:], /SourceCache/AddressBookUI_Sim/AddressBookUI-1553/Framework/Sources/CNUIContact/CNContact.m:855

我什至不知道 CNContact 是什么类或者为什么它是错误的。

最佳答案

我认为您尝试使用的属性有误。而是尝试这个:

#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <AddressBookUI/AddressBookUI.h>

@interface PersonViewController : UIViewController <ABPersonViewControllerDelegate> 
{
ABPersonViewController *personController;
}

- (void) displayContactInfo: (ABRecordRef)person;

@end

委托(delegate)的实现(PersonViewController.m):

#import "PersonViewController.h"

@implementation PersonViewController

- (void) viewDidLoad
{
}

 - (void) viewDidUnload
 {
[personController release];
 }

  - (void) displayContactInfo: (ABRecordRef)person
{
personController = [[ABPersonViewController alloc] init];
[personController setDisplayedPerson:person];
[personController setPersonViewDelegate:self];
[personController setAllowsEditing:NO];
personController.addressBook = ABAddressBookCreate();   

personController.displayedProperties = [NSArray arrayWithObjects:
    [NSNumber numberWithInt:kABPersonPhoneProperty], 
    nil];

[self setView:personController.view];
}

 - (BOOL) personViewController:(ABPersonViewController*)personView shouldPerformDefaultActionForPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifierForValue
{
// This is where you pass the selected contact property elsewhere in your program
[[self navigationController] dismissModalViewControllerAnimated:YES];
return NO;
}

@end

关于ios - 显示 ABPersonViewController 的这段代码有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19238278/

相关文章:

ios - 将 Base 64 图像字符串 POST 到 iOS 上的服务器

ios - 如何使用 Reactive Cocoa 以正确的方式链接信号?

ios - UIPickerview 未出现在正确的位置

objective-c - 如果将自动释放对象标记为自动释放会发生什么

objective-c - 绑定(bind)出了问题,无法找出原因

ios - 我如何在 iOS 中获取捕获的图像路径?

ios - 异步下载多个图像

android - 我需要在 Xamarin Forms 按钮内设置格式化文本(两种不同大小)

ios - 使用 compass Swift 指向位置

ios - 将数据从 ViewController 传递到实例化的自定义 View Controller