【问题标题】:Check if ABMultiValueRef is has no values检查 ABMultiValueRef 是否没有值
【发布时间】:2014-07-02 14:57:50
【问题描述】:

我想检查我的用户通讯录中的联系人是否有电话号码。如果他这样做,我想在 UITableView 中显示该名称

我尝试检查phoneNumbers != nil,但这不起作用。这是我的全部代码:

ABMultiValueRef phoneNumbers = ABRecordCopyValue(person, kABPersonPhoneProperty);

if(phoneNumbers != nil){
  [_numbers addObject:[NSString stringWithFormat:@"%@", phoneNumbers]];
}

【问题讨论】:

  • 那么,当 ABRecord 没有 phone 属性时,phoneNumbers 的值是多少?你不能只检查那个值而不是 nil 吗?
  • 不是真的,当我记录它时显示 ABMultiValueRef 0x10ab8bf40 with 0 value(s)\n

标签: ios objective-c c abaddressbooksource


【解决方案1】:

使用ABMultiValueGetCount 检查phoneNumbers 中是否有任何值。

基于问题的示例:

ABMultiValueRef phoneNumbers = ABRecordCopyValue(person, kABPersonPhoneProperty);

if(ABMultiValueGetCount(phoneNumbers)){
    [_numbers addObject:[NSString stringWithFormat:@"%@", phoneNumbers]];
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-08-09
    • 2016-07-30
    • 1970-01-01
    • 2017-12-04
    • 1970-01-01
    • 1970-01-01
    • 2012-02-09
    • 1970-01-01
    相关资源
    最近更新 更多