2012-09-20 33 views
0

我使用電弧在我application.In我的申請,我在UIWebView中發揮的YouTube視頻和視頻鏈接來自數據庫,我把網址中的UITableViewCell,我得到了內存接收warning.My數據庫記錄是60 任何一個可以幫助我out.Thank你提前如何處理iPhone中的自動引用計數內存警告?

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath 
{ 
    NSString *CellIdentifier = [NSString stringWithFormat:@"Cell%d",indexPath.row]; 
    VideoCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    if (cell==nil) 
    { 
     cell =[[VideoCell alloc] initWithStyle:UITableViewCellStyleSubtitle  reuseIdentifier:CellIdentifier]; 
     cell.selectionStyle=UITableViewCellSelectionStyleNone; 

     [cell.lblVid_Name setText:[[arr_Video  objectAtIndex:indexPath.row]valueForKey:@"Video_Name"]]; 
    [cell.lblVid_Desc setText:[[arr_Video objectAtIndex:indexPath.row]valueForKey:@"Video_Desc"]]; 

     NSString *url=[NSString stringWithFormat:@"%@",[[[arr_Video objectAtIndex:indexPath.row]valueForKey:@"Video_Link"]lastPathComponent]]; 

     NSString *youTubeVideoHTML [email protected]"<html><head> <meta name = \"viewport\" content = \"initial-scale = 1.0, user-scalable = no, width = \"%f\"/></head> <body style=\"margin-top:0px;margin-left:0px\"> <iframe width= \"%f\" height=\"%f\" src = \"http://www.youtube.com/embed/%@?showinfo=0\"frameborder=\"0\" hd=\"1\" allowfullscreen/>></iframe></div></body></html>"; 
     NSString *html = [NSString stringWithFormat:youTubeVideoHTML,cell.webView_Video.frame.size.width,cell.webView_Video.frame.size.width, cell.webView_Video.frame.size.height,url]; 


     [cell.webView_Video loadHTMLString:html baseURL:nil]; 
     url=nil; 
     youTubeVideoHTML=nil; 
     html=nil; 

} 
return cell; 

}

+0

請發表您的相關代碼。 –

回答

4

所以60個細胞生成,每一方都將加載視頻 - 不會在吃了大量的內存?你不想顯示可能的視頻,只有當用戶點擊一個單元格時才加載它們?然後,一旦細胞離線播放視頻?

3

您使用的是大量的細胞,而不是重複使用細胞:

NSString *CellIdentifier = [NSString stringWithFormat:@"Cell%d",indexPath.row]; 
VideoCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

這意味着你正在創建於各行的單元格!

你應該重用超出屏幕的細胞,不會再創建一個新

使用只是一個CellIdentifier所有單元,然後管理該呼叫的數據(改變細胞的內部值),但重新使用舊的單元格。

,如果你可以隨時在屏幕上看到剛剛10個細胞,你應該分配/只創建10個細胞的對象,即使你的數組​​包含60個或多個對象,但是您創建的60個細胞/對象!