0

アプリケーションでアークを使用しています。アプリケーションでは、UIWebView で YouTube ビデオを再生しました。ビデオの URL はデータベースから取得され、その URL を UITableViewCell に配置すると、メモリが警告を受け取りました。データベース レコードは 60 です。だれでも助けてくれます。前もって感謝します

- (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 =@"<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;

}

4

2 に答える 2

4

つまり、60個のセルが作成され、それぞれがビデオをロードします。これにより、大量のメモリが消費されませんか?可能なビデオを表示して、ユーザーがセルをタップしたときにのみロードしませんか?次に、セルが画面外になったら、ビデオをリリースしますか?

于 2012-09-20T15:36:26.303 に答える
3

多くのセルを使用しており、セルを再利用していません:

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

これは、行ごとにセルを作成していることを意味します!

新しいセルを再度作成するのではなく、画面外のセルを再利用する必要があります

すべてのセルに CellIdentifier のみを使用し、その呼び出しのデータを管理 (セルの内部値を変更) しますが、古いセルを再利用します。

いつでも画面に 10 個のセルしか表示できない場合は、配列に 60 個以上のオブジェクトが含まれている場合でも、10 個のセル オブジェクトを割り当て/作成する必要がありますが、60 個のセル/オブジェクトを作成します!

于 2012-09-20T15:40:11.343 に答える