gpt4 book ai didi

ios - 在 UITableViewCell 中设置 iOS 通讯簿图片

转载 作者:行者123 更新时间:2023-12-01 19:24:16 28 4
gpt4 key购买 nike

我正在尝试将 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];

然后可以通过调用 UITabelView 中的数组将图像正常加载到单元格中
cell.personImage.image = [peopleImage objectAtIndex:indexPath.row];

关于ios - 在 UITableViewCell 中设置 iOS 通讯簿图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8719964/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com