2009-08-06 28 views
0
imgBiteSpot.clipsToBounds=YES; 
    NSData *imageData = [[[NSData alloc]init]autorelease]; 
    imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:ObjBitSpot.StrImagePath]]; 
    if(imageData==0) 
    { 
     imgBiteSpot.image=[UIImage imageNamed:@"img-not-found.gif"]; 
    } 
    else { 
     UIImage *imgs = [[UIImage alloc] initWithData:imageData]; 
     UIGraphicsBeginImageContext(CGSizeMake(88,88)); 
     [imgs drawInRect:CGRectMake(0.0, 0.0, 88.0, 88.0)]; 
     UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext(); 
     UIGraphicsEndImageContext(); 
     imgBiteSpot.image=newImage; 
     [imgs release]; 
    } 

iPhone中的圖像加載問題? - 來自webservice


我已經將圖像載入 imgBiteSpot。 圖像從web服務加載。問題是它需要太多時間(35秒到1分鐘)。

如果我刪除圖像 - >代碼/加載,反應時間僅爲0.2秒。

減少圖像加載過程的時間的解決方案是什麼?

在此先感謝您的幫助。

回答

3

您正在使用NSData的方法dataWithContentsOfURL:,它從服務器同步加載數據,從而阻塞線程直到接收到圖像。

你應該做的是將空白或「加載」圖像加載到你的UIImage中,然後使用NSURLConnection異步下載圖像並在完成時顯示它。請參閱NSURLConnection參考文獻和URL Loading System文檔。