【发布时间】:2008-11-13 03:46:51
【问题描述】:
我正在向用户显示地址簿视图,并让他们单击联系人并选择电话号码。如果他们选择电话号码,我想将电话号码作为整数获取,将联系人姓名作为 NSString 获取。
我尝试过使用以下代码:
//printf("%s\n",[[(NSArray *)ABMultiValueCopyArrayOfAllValues(theProperty) objectAtIndex:identifier] UTF8String]);
//CFArrayRef *arrayString = [[(NSArray *)ABMultiValueCopyArrayOfAllValues(theProperty) objectAtIndex:identifier] UTF8String];
NSArray *arrayString = [(NSArray *)ABMultiValueCopyArrayOfAllValues(theProperty) objectAtIndex:identifier];
printf("%s\n", arrayString);
这段代码在这个方法里面:
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier
我正在检查用户是否使用此代码选择了电话号码:
if (propertyType == kABStringPropertyType)
{
[self wrongSelection];
}
else if (propertyType == kABIntegerPropertyType)
{
[self wrongSelection];
}
else if (propertyType == kABRealPropertyType)
{
[self wrongSelection];
}
else if (propertyType == kABMultiStringPropertyType)
{
//This is the phone number...
我可以使用 printf 获取要在控制台中显示的电话号码,但是我不知道如何将其转换为整数以及如何获取联系人姓名,即使所选属性不是一个人的姓名。
另外,我正在做的事情似乎效率很低。有没有更好的方法来做到这一点?
编辑:如果我不能将它们存储为 int,则可以使用字符串。我只是不知道如何从那个数组变成一个实际的字符串。如果我将其转换或保存为 UTF8String,我总是会遇到一些错误。
【问题讨论】:
标签: iphone objective-c cocoa-touch