嗨,我正在创建自定义通讯簿,我只想让这个拥有电子邮件地址的用户一切正常,但是当我尝试在 tableview 中显示图像时,它给了我EXCBAD Error
。我有这样的代码
ABAddressBookRef addressBook = ABAddressBookCreate();
CFArrayRef people = ABAddressBookCopyArrayOfAllPeople(addressBook);
for (CFIndex i = 0; i < CFArrayGetCount(people); i++) {
ABRecordRef person = CFArrayGetValueAtIndex(people, i);
ABMultiValueRef emails = ABRecordCopyValue(person, kABPersonEmailProperty);
for (CFIndex j=0; j < ABMultiValueGetCount(emails); j++) {
UIImage *img;
if(ABPersonHasImageData(person))
{
// img = [UIImage imageWithData:(NSData *)ABPersonCopyImageDataWithFormat(person,kABPersonImageFormatThumbnail)];
img = [UIImage imageWithData:(NSData *)ABPersonCopyImageData(person)];
// if(img != nil)
// {
// [arrImage addObject:img];
// }
// else
// {
img = [UIImage imageNamed:@"icon-9.png"];
[arrImage addObject:img];
// }
}else
{
img = [UIImage imageNamed:@"icon-9.png"];
[arrImage addObject:img];
}
NSString* email = (NSString*)ABMultiValueCopyValueAtIndex(emails, j);
// [arrImage addObject:img];
[arrEmail addObject:email];
[img release];
[email release];
}
CFRelease(emails);
}
CFRelease(addressBook);
CFRelease(people);
在上面的代码中,我正在获取图像并将图像存储在 NSMutableArray 中,它将被完美地存储。但是当我要在下面的代码中显示图像时
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UIImageView* imagePhoto;
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableFriends dequeueReusableCellWithIdentifier:CellIdentifier];
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
imagePhoto= [[[UIImageView alloc] initWithFrame:CGRectMake(43.0,10.0,40, 40)] autorelease];
if ([arrEmail count] != 0)
{
imagePhoto.image = [arrImage objectAtIndex:indexPath.row];
[cell.contentView addSubview:imagePhoto];
cell.detailTextLabel.text = [NSString stringWithFormat:@"%@",[arrEmail objectAtIndex:indexPath.row]];
cell.detailTextLabel.textColor = [UIColor whiteColor];
}
return cell;
}
当从这里调用图像时,它可以完美地工作,img = [UIImage imageNamed:@"icon.png"];
但是当从地址簿调用图像时,它会给我错误EXCBAD Error
,说明该代码有什么问题?如何将图像存储在 NSMutabeArray 中并显示图像?
嘿,帮帮我,任何人都可以帮助我或建议我像Google Latitude 那样实现,你可以在 iPhone 通讯录中添加朋友看到从通讯录中获取图像请帮助我....