【发布时间】:2012-06-30 20:02:00
【问题描述】:
我正在使用 kABPersonPhoneProperty 从通讯录中获取 iPhone“电话号码”。但是,一旦我运行该程序并且只有一个电话号码出现,即使联系人有手机号码、家庭号码和 iphone 号码。请帮忙,我希望能从每个联系人那里获得所有电话号码。谢谢。
完整方法:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"SimpleCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
// cell.textLabel.text = [people objectAtIndex:indexPath.row];
ABRecordRef record = (__bridge ABRecordRef) [people objectAtIndex:[indexPath row]];
NSString *firstName = (__bridge_transfer NSString*)ABRecordCopyValue(record, kABPersonFirstNameProperty);
NSString *lastName = (__bridge_transfer NSString*)ABRecordCopyValue(record, kABPersonLastNameProperty);
NSLog(@"FirstName %@, LastName %@", firstName, lastName);
cell.nameLabel.text = [NSString stringWithFormat:@"%@ %@", firstName, lastName];
ABMultiValueRef mainPhone = ABRecordCopyValue(record, kABPersonPhoneProperty);
for (CFIndex i = 0; i < ABMultiValueGetCount(mainPhone); i ++) {
NSString *phoneMobileNumber = (__bridge_transfer NSString*)ABMultiValueCopyValueAtIndex(mainPhone, i);
cell.telNo.text = [NSString stringWithFormat:@"%@ %@" , home, phoneMobileNumber];
NSLog(@"%@,%@", home, phoneMobileNumber);
}
return cell;
}
【问题讨论】:
-
文本应该出现在哪里?在表格视图单元格中?
-
是在表格视图单元格中,并且表格视图单元格具有联系人姓名和联系人号码的姓名和联系人号码字段。如何在联系号码字段中显示联系号码结果(包括 Main、Mobile 和 Iphone 在内的所有联系号码)?
-
那么这是在
<UITableViewDataSource>方法中吗? -
我正在 (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath from
协议中实现。 -
你能把整个
cellForRowAtIndexPath:方法贴出来吗?
标签: iphone objective-c ios5 xcode4.3