【问题标题】:How to retrieve kABPhoneNumber from Address Book in Cocoa with multiValues?如何从具有多值的 Cocoa 通讯录中检索 liBPhoneNumber?
【发布时间】:2014-10-05 14:09:44
【问题描述】:

我正在尝试从 ABRecord 中提取电话号码并将其放入 NSTableView。它记录了数字,但是当滚动 tableView 并尝试获取更多数据时应用程序崩溃。我检索号码的方式是否正确?我不清楚为什么有时无法将其加载到单元格中。

-(NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn*)tableColumn row:(NSInteger)row
{

contactCell *cellView = [tableView makeViewWithIdentifier:tableColumn.identifier owner:self];

if( [tableColumn.identifier isEqualToString:@"cell"] )
{
    ABPerson *indexedPerson = contactsArr[row];
    ABRecord *record = contactsArr[row];

    NSString *numberString = @"";

    NSString *nameInfo = [NSString stringWithFormat:@"%@ %@",
                          [indexedPerson valueForKey:kABFirstNameProperty],
                          [indexedPerson valueForKey:kABLastNameProperty]];
    //get the number
    ABMutableMultiValue *multiValue = [record valueForProperty:kABPhoneProperty];

    NSLog(@"currentPerson: %@",indexedPerson);

    //see if there is data in the multi value
    if ([multiValue valueAtIndex:1]) {
        numberString = [multiValue valueAtIndex:1];
    } else {
        numberString = @"";
    }

    NSLog(@"%@ test", numberString);

    //set the strings
    [cellView.nameField setTitle:nameInfo];
    //set field in cell
    [cellView.numberField setTitle:numberString];

    return cellView;
}
return cellView;
}

【问题讨论】:

    标签: objective-c macos cocoa


    【解决方案1】:

    我不是检查索引 0,而是检查索引 1。在 if 语句中更改为索引 0 检查多值中的数据解决了这个问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-12
      • 2017-04-04
      • 2023-03-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多