views:

84

answers:

1

Hi all,

In my aplication I need to display an image or images on tableview cells depending on their availability in database. What I have done is I have planted four webviews [to show images from urls] and I'm hiding or showing these depending on their availability.

There might also be a case when there's no image, when I'm hiding webviews entirely.

But after random scrolling my application is crashing. Also, while scrolling it's showing me the newer images over older. So, I'm able to see at first one image, then after scrolling through the same cell, two images are led over one another[some part of earlier photo is visible] and so on. Can this be because of cell-reusability? What is the ideal way to about this issue?

EDIT:

I'm using following code:

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

Thanx in advance.

A: 

coupling!!! cells are being reused! what if cell is being reused even before those web views get the results? please pull out the image loading operation from your cell and do it in your controller. Cell must have four image views. And controller should pass the images for them.

Manjunath