我正在尝试将 AddressBookUI API 集成到我的 iOS 5 应用程序中,以在表格视图中显示选定的内容。我已经能够实现 AddressBook Picker 并对其进行设置,以便当用户从他们的地址簿中选择一个人时,它会填充 TableView 中单元格的标签。我还希望它能够在同一单元格中显示所选人员的图像(如果存在),如果不存在则显示默认的缺失图片图像。
我无法理解如何将名称和图像数据存储在同一个 TableView 单元格中。
任何人都对我如何实现这一点有任何建议。我已阅读开发人员文档并且知道我应该使用 ABPersonCopyImageDataWithFormat 命令。我似乎无法将它实现到 tableview 单元格中。
以下是我到目前为止的代码片段:
// Store the name into memory when the user selects, then dismiss the view.
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person
{
NSString *selectedPerson = (__bridge NSString *)ABRecordCopyCompositeName(person);
[people insertObject:selectedPerson atIndex:0];
if (ABPersonHasImageData(person) == TRUE) {
NSLog(@"Person has an image!");
} else {
NSLog(@"Person does not have an image.");
}
[self dismissModalViewControllerAnimated:YES];
[self.tableView reloadData];
return NO;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
PartyCell *cell = (PartyCell *)[tableView dequeueReusableCellWithIdentifier:@"Cell"];
cell.backgroundView = [[GradientView alloc] init];
cell.personLabel.text = [people objectAtIndex:indexPath.row];
cell.personImage.image = [UIImage imageNamed:@"missing.png"]; // THIS NEEDS TO DISPLAY THE SELECTED USERS PICTURE. CURRENTLY SHOWS A DEFAULT USER.
return cell;
}
谢谢!