动态显示桌面视图单元格上的图像

问题描述:

在我的应用程序中,我需要在桌面视图单元上显示一个或多个图像,具体取决于它们在数据库中的可用性。我所做的是我已经种植了四个网页浏览器[显示来自网址的图片],并且根据其可用性隐藏或显示这些图片。动态显示桌面视图单元格上的图像

当我完全隐藏网页浏览时,可能还存在没有图像的情况。

但随机滚动后我的应用程序崩溃。另外,在滚动时,它会向更旧的图像显示新图像。所以,我能够首先看到一幅图像,然后在滚动相同的单元格之后,两幅图像相互引导[前一张照片的某些部分可见]等等。这可能是因为细胞可重复使用吗?关于这个问题的理想方式是什么?

编辑:

我用下面的代码:

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提前。

+2

我没有在这里回答你的崩溃问题,但你不需要web视图来显示来自URL的图像。您可以使用UIImageView并从URL设置图像。 (UIImage * image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSUrl NSURL URLWithString:MyURL]]];)这会容易得多。 – lukya 2010-07-20 06:51:44

+1

另外,发布一些代码。这会让你更容易知道你的应用崩溃的原因。 – lukya 2010-07-20 06:52:43

+0

Thanx lukya你的回应。我已经更新了我的问题。请检查。 – neha 2010-07-20 07:01:38

联轴器!!!细胞正在被重复使用!甚至在这些网页浏览获得结果之前,单元格是否被重用?请从您的手机中取出图像加载操作并在您的控制器中进行。单元格必须有四个图像视图。控制器应该为他们传递图像。