0
我試圖從ABRecord中提取電話號碼並將其放入NSTableView中。它記錄了這個數字,但是當tableView被滾動並且試圖獲得更多數據時,應用程序崩潰。我是以正確的方式檢索數字的方式嗎?它不清楚爲什麼它有時無法將它加載到單元格中。如何使用multiValues在Cocoa的地址簿中檢索kABPhoneNumber?
-(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;
}