作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试将 AddressBookUI API 集成到我的 iOS 5 应用程序中,以在表格 View 中显示选定的内容。我已经能够实现 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;
}
最佳答案
找到了一个简单的解决方案:每次将所选联系人的图像存储在索引 0 处的新 NSMutableArray 中。
UIImage *image =[UIImage imageWithData:(__bridge NSData *)ABPersonCopyImageDataWithFormat(person, kABPersonImageFormatThumbnail)];
[peopleImage insertObject:image atIndex:0];
cell.personImage.image = [peopleImage objectAtIndex:indexPath.row];
关于ios - 在 UITableViewCell 中设置 iOS 通讯簿图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8719964/
我是一名优秀的程序员,十分优秀!