2010-07-20 86 views
0

在我的應用程序中,我需要在桌面視圖單元上顯示一個或多個圖像,具體取決於它們在數據庫中的可用性。我所做的是我已經種植了四個網頁瀏覽器[顯示來自網址的圖片],並且根據其可用性隱藏或顯示這些圖片。動態顯示桌面視圖單元格上的圖像

當我完全隱藏網頁瀏覽時,可能還存在沒有圖像的情況。

但隨機滾動後我的應用程序崩潰。另外,在滾動時,它會向更舊的圖像顯示新圖像。所以,我能夠首先看到一幅圖像,然後在滾動相同的單元格之後,兩幅圖像相互引導[前一張照片的某些部分可見]等等。這可能是因爲細胞可重複使用嗎?關於這個問題的理想方式是什麼?

編輯:

我用下面的代碼:

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

回答

0

聯軸器!!!細胞正在被重複使用!甚至在這些網頁瀏覽獲得結果之前,單元格是否被重用?請從您的手機中取出圖像加載操作並在您的控制器中進行。單元格必須有四個圖像視圖。控制器應該爲他們傳遞圖像。

相關問題