2010-07-20 14 views
0

필자는 데이터베이스에서의 가용성에 따라 tableview 셀에 이미지 나 이미지를 표시해야합니다. 내가 한 일은 웹 사이트를 4 개 심었고 가용성에 따라 숨기거나 표시하는 것입니다.동적으로 테이블 뷰 셀에 이미지 표시

웹 뷰가 완전히 숨겨져있을 때 이미지가없는 경우도있을 수 있습니다.

하지만 임의로 스크롤 한 후 내 응용 프로그램이 충돌합니다. 또한 스크롤하는 동안 나이가 들어감에 따라 새로운 이미지가 표시됩니다. 그래서 처음에는 하나의 이미지를 볼 수 있습니다. 그런 다음 동일한 셀을 스크롤 한 후에 두 이미지가 서로 뒤덮여 있습니다. [이전 사진의 일부가 보입니다.] 등등. 이것은 세포 재사용 성 때문일 수 있습니까? 이 문제에 대한 이상적인 방법은 무엇입니까?

편집 : 나는 다음 코드를 사용하고

: 사전에

noOfPhotos = [photos_array count]; 

if(noOfPhotos > 0){ 

    commentWhenWebviewNotThere.alpha = 0.0;   //Things that are not visible when images are there 
    noOfCommentsWhenWebviewNotThere.alpha = 0.0; 
    commentsLblWhenWebviewAbset.alpha = 0.0; 

    image1.hidden = NO; 
    image2.hidden = NO; 
    image3.hidden = NO; 
    image4.hidden = NO; 

    commentsLblWhenWebview.alpha = 1.0; 
    noOfComments.alpha = 1.0; 
    comment.alpha = 1.0; 

for(NSInteger x = 0; x < noOfPhotos; x++){ 
    photoName = [photos_array objectAtIndex:x]; 

    NSString *urlAddress = [NSString stringWithFormat:@"%@",photoName]; 
    NSURL *url = [NSURL URLWithString:urlAddress];   
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];    

    if(x == 0){ 
     image1 = [[UIWebView alloc] initWithFrame:CGRectMake(10, comment.frame.origin.y - 5, 60, 60)]; 
    [image1 loadRequest:requestObj];    //Load the request in the UIWebView. 
     [self addSubview:image1]; 
    } 

    else if(x == 1){ 
     image2 = [[UIWebView alloc] initWithFrame:CGRectMake(88, comment.frame.origin.y - 5, 60, 60)]; 

    [image2 loadRequest:requestObj];    //Load the request in the UIWebView. 
     [self addSubview:image2]; 

    } 

    else if(x == 2){ 
     image3 = [[UIWebView alloc] initWithFrame:CGRectMake(169, comment.frame.origin.y - 5, 60, 60)]; 

     [image3 loadRequest:requestObj];    //Load the request in the UIWebView. 
     [self addSubview:image3]; 

    } 

    else if(x == 3){ 
     image4 = [[UIWebView alloc] initWithFrame:CGRectMake(251, comment.frame.origin.y - 5, 60, 60)]; 

     [image4 loadRequest:requestObj];    //Load the request in the UIWebView. 
     [self addSubview:image4]; 

    } 

} 
} 

else{ 
    commentWhenWebviewNotThere.alpha = 1.0; //Should be visible when images are not there 
    noOfCommentsWhenWebviewNotThere.alpha = 1.0; 
    commentsLblWhenWebviewAbset.alpha = 1.0; 

    commentsLblWhenWebview.alpha = 0.0; 
    noOfComments.alpha = 0.0; 
    comment.alpha = 0.0; 

    image1.hidden = YES; 
    image2.hidden = YES; 
    image3.hidden = YES; 
    image4.hidden = YES; 
} 

고맙습니다.

+2

여기에 문제가 해결되지 않았지만 URL에서 이미지를 표시 할 때 웹보기가 필요하지 않습니다. UIImageView를 사용하고 URL에서 이미지를 설정할 수 있습니다. (UIImage * image = [UIImage imageWithData : [NSData dataWithContentsOfURL : [NSUrl NSURL URLWithString : MyURL]]]) 훨씬 쉬울 것입니다. – lukya

+1

또한 일부 코드를 게시하십시오. 그러면 앱이 왜 충돌하는지 쉽게 알 수 있습니다. – lukya

+0

고맙습니다. 내 질문을 업데이트했습니다. 체크 아웃하십시오. – neha

답변

0

커플 링 !!! 세포가 재사용되고있다! 웹보기가 결과를 얻기도 전에 셀을 다시 사용한다면 어떻게 될까요? 셀에서 이미지로드 작업을 빼내고 컨트롤러에서 수행하십시오. 셀에는 4 개의 이미지 뷰가 있어야합니다. 그리고 컨트롤러는 이미지를 전달해야합니다.

관련 문제