2010-03-04 30 views
1

我在導航控制器中遇到了我的UITableView問題。 當我將數據添加到表格中時,我使用另一個類來下載圖像以顯示在該表格中,而所有這些功能都很棒,但如果在下載圖像的過程中,我會回到導航控制器應用程序中的先前視圖崩潰。如何檢查視圖是否有效iphone

這是我的代碼解釋進一步

- (void)connectionDidFinishLoading:(NSURLConnection *)connection 
{ 
    // Set appIcon and clear temporary data/image 
    UIImage *image = [[UIImage alloc] initWithData:self.activeDownload]; 
    UIImage *appIcon; 

    if (image.size.width != kAppIconHeight && image.size.height != kAppIconHeight) 
    { 
     CGSize itemSize = CGSizeMake(125, 85); 
     UIGraphicsBeginImageContext(itemSize); 
     CGRect imageRect = CGRectMake(0.0, 0.0, itemSize.width, itemSize.height); 
     [image drawInRect:imageRect]; 
     appIcon = UIGraphicsGetImageFromCurrentImageContext(); 
     ///UIGraphicsEndImageContext(); 
    } 
    else 
    { 
     appIcon = image; 
     //self.appRecord.appIcon = image; 
    } 

    self.activeDownload = nil; 


    // Release the connection now that it's finished 
    self.imageConnection = nil; 

    // call our delegate and tell it that our icon is ready for display 
    if(delegate != nil) 
    [delegate appImageDidLoad:self.indexPathInTableView imaged:appIcon ]; 

[image release]; 

} 

的appImageDidLoad是存在於我的UITableView視圖的方法。

有沒有一種方法可以檢查UITableView是否在我的imagedownload類中有效,所以我不知道發送圖像。

在此先感謝。

+0

崩潰發生在哪裏? – 2010-03-07 08:08:33

回答

1

這次崩潰是由於委託人在圖像準備好的時候獲得釋放!

試試這個在ViewWillDisappear

// terminate all pending download connections 
NSArray *allDownloads = [self.imageDownloadsInProgress allValues]; 
[allDownloads performSelector:@selector(cancelDownload)]; 
+0

這不是解決問題。 此代碼正在運行時程序崩潰。 – iosdevnyc 2010-03-06 19:13:26

1

這是這個崩潰的解決方案。

-(void)viewDidDisappear:(BOOL)animated 
{ 
    [super viewDidDisappear:animated]; 

    // terminate all pending download connections 

    NSArray *allDownloads = [self.imageDownloadsInProgress1 allValues]; 

    [allDownloads makeObjectsPerformSelector:@selector(cancelDownload)]; 

}