2012-04-06 2 views
2

안녕하세요,이 사용자 지정 주소록을 만들고 있는데 전자 메일 주소가있는 사용자 만 완벽하게 작동하지만 테이블 뷰에서 이미지를 표시하려고하면 EXCBAD Error이 표시됩니다. 나는 그것을 완벽하게 저장 될 것입니다있는 NSMutableArray에 이미지 저장 이미지를 가져 오는하고 위의 코드에서 여기주소록에서 이미지를 가져 와서 NSmutablearray에 저장했지만 아이폰 SDK에 'EXCBAD 오류'가 표시됩니다.

  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); 

같은 코드가 있습니다. 내가 이미지가 여기 img = [UIImage imageNamed:@"icon.png"]; 만에서 호출 될 때 아래 코드

-(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; 
} 

가 perfecly 작동에 이미지를 표시하기 위하여려고 할 때 이미지가 주소록에서 호출 될 때 그러나 그것은 나에게 그 코드에 무슨 잘못 EXCBAD Error의 오류를 제공 ? NSMutabeArray에 이미지를 저장하고 이미지를 표시하려면 어떻게해야합니까?

헤이 어떤 몸이 좀 도와 또는 내가 당신이보고 난 그냥 내 모든 코드가 좋은 만 작동하고 어떤이 응용 프로그램의 기능과 같은 몇 가지를 구현하려는 아이폰 주소록에서 친구를 추가 할 수 있습니다이의 Google Latitude 처럼 구현하기 위해 제안 할 수 있습니다 도와 주소록에서 이미지를 가져올 수 없습니다. ...

+0

아무도 도와주세요. –

답변

4

는 ARC 모드에서 프로젝트를 구축하고 가정

ABRecordRef

의 인스턴스입니다.

 
NSData *imgData = (__bridge_transfer NSData *) ABPersonCopyImageDataWithFormat(personrecord, kABPersonImageFormatThumbnail); 

      if (imgData) 
      { 
       UIImage *personImage = [UIImage imageWithData:imgData]; 
       imgData = nil; 
       [dict setValue:personImage forKey:@"UserImage"]; 
      } 
      else 
      { 
       UIImage *personImage = [UIImage imageNamed:@"defalt_contact_img.png"]; 
       [dict setValue:personImage forKey:@"UserImage"]; 
      } 

당신은 귀하의 요구 사항에 맞게 코드를 조작 할 수

, 내가 사전을 이용하고 이미지를 저장하는 배열의 addObject 방법을 사용할 수 있도록 배열을 사용하고 난 항상 얻을 것을 선호 주소록의 레코드를 여러 사전으로 변경 가능한 배열에 저장하면 레코드 조작이 쉬워집니다.

0

이미지가 있는지 여부를 확인해야합니다.

 
NSData *data = (NSData *)ABPersonCopyImageData(person); 
UIImage *img = [UIImage imageWithData:data]; 

if(img != nil) 
{ 
    // assign the image here 
} 
else 
{ 
    img = [UIImage imageNamed:@"icon.png"]; 
} 

코드를 삭제했습니다. 나는 이것이 도움이 될 것 같아요. 이미지를 사용할 수 또는

if(ABPersonHasImageData(person)) { 
     UIImage* img = [UIImage imageWithData:(NSData *)ABPersonCopyImageDataWithFormat(person, kABPersonImageFormatThumbnail)] 
    } 
+0

나는 이것을 시도했지만 여전히 같은 오류를 준다. 어느 누구도 나를 도울 수 있습니까? –

+0

여기에 더 많은 코드를 붙여 넣을 수 있습니까 ?? –

+0

지금 물어볼 필요가있는 것이 있으면 저에게 말하십시오. –

2

는 처음있는 NSData의 이미지를 변환 및 배열에 추가 할 필요가 확인하려고 , 그 다음 이미지를 보여주는 동안 NSdata를 이미지로 변환합니다. 희망이 도움이됩니다. 나는이

personrecord 같은 NSMutableDictionary의 객체에 이미지를 저장 한

+0

나는 내 코드를 본적이있다. 이미 시도했으나 작동하지 않는다. –

0
당신이 직접 이미지 객체를 추가 할 수 없습니다

및 배열을 사용하지 않는 경우

+0

나는 당신이 제안한 것처럼 많이 시도했지만, 나에게이 문제에 대한 실행 코드를 게시 해 준다. ? –