簡體   English   中英

重用UITableViewCell不起作用

[英]Reusing UITableViewCell doesn't work

我正在使用MonoTouch,並且有一個自定義單元格視圖,該視圖不會重復使用。

  1. 我嘗試設置IBUIReuseIdentifier
  2. 我嘗試將string和NSString用於_cellId類型
  3. 我嘗試過重新創建該項目。
  4. 有趣的是,我還有其他自定義單元可以正常工作,但是我創建的任何新單元都不會被重用。 我不太確定下一步要去哪里。

謝謝。

public override UITableViewCell GetCell (UITableView tableView, 
                                         NSIndexPath indexPath)
{           

    UITableViewCell cell =  tableView.DequeueReusableCell(_cellId);
    LibraryItem item = _items[indexPath.Row];
    LibraryCellView cellController = null;

    if (cell == null)
    {
        cellController = new LibraryCellView();
        cell = cellController.Cell; // cellController.Cell;

        cell.Tag = Environment.TickCount;

        _cellControllers[cell.Tag] = cellController;
        Console.WriteLine("Cell New");
    }
    else
    {
        cellController = _cellControllers[cell.Tag];
        Console.WriteLine("Cell Reused");
    }

    cellController.Name = item.Name;
    cellController.Date = item.CreatedDate.ToShortDateString();
    cellController.Shared = item.IsShared ? "Shared":"";
    cellController.Count = item.Count.ToString();
    cellController.ImageCoverId1 = item.CoverPictureId1;    

    return cell;
}

一些注意事項

您是否為每個單元使用控制器?

然后,您在哪里聲明_cellId

最后,注意cell.Tag = Environment.TickCount; Environment.TickCount調用可能會導致問題,因為它可能足夠快來創建相等的標簽。

這樣說,我認為您實際上不需要每個單元格都有一個控制器(如果使用的話)。 您可以創建一個擴展UITableViewCell的自定義類,並按原樣使用它。 如果您使用的是xib界面,我真的建議您閱讀創建帶有單獨觸摸的正確方式的custom-uitableviewcells帖子。

希望能幫助到你。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM