2012-01-03 4 views
1

AddressBookUI API를 iOS 5 앱에 통합하여 선택한 내용을 테이블보기에 표시하려고합니다. AddressBook Picker를 구현하고 사용자가 주소록에서 사람을 선택하면 TableView에서 셀의 레이블을 채우도록 설정할 수있었습니다. 또한 같은 셀에있는 선택된 사람의 이미지와 존재하지 않는 경우 누락 된 기본 이미지를 표시 할 수 있기를 바랍니다.UITableViewCell의 iOS 주소록 이미지 설정

같은 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; 
} 

감사합니다!

답변

3

간단한 해결책을 찾았습니다 : 매번 인덱스 0에 새로운 NSMutableArray에 선택된 연락처의 이미지를 저장하십시오.

UIImage *image =[UIImage imageWithData:(__bridge NSData *)ABPersonCopyImageDataWithFormat(person, kABPersonImageFormatThumbnail)]; 

     [peopleImage insertObject:image atIndex:0]; 

이미지는 내가 코드의 두 라인을 시도 한 UITabelView

cell.personImage.image = [peopleImage objectAtIndex:indexPath.row]; 
0

먼저, ABRecordRef에서있는 UIImage 얻을 :

[UIImage imageWithData:(NSData *)ABPersonCopyImageDataWithFormat(person, kABPersonImageFormatThumbnail)]; 

그런 다음, 당신이있는 UITableViewCell의 이미지 뷰의 이미지를 설정할 수 있습니다와 같은 : 당신이 도움이 될 수

[[cell imageView] setImage: image]; 

커플 다른 링크 :

http://www.chrisdanielson.com/tag/uitableviewcell/

http://goddess-gate.com/dc2/index.php/post/421

+0

의 배열을 호출하여 세포에 정상처럼로드 할 수 있지만 나를 위해 작동하지 않습니다. 내가 작업중인 코드의 두 섹션으로 원래 게시물을 편집했습니다. – Brian