[英]Reusing UITableViewCell doesn't work
我正在使用MonoTouch,並且有一個自定義單元格視圖,該視圖不會重復使用。
NSString
用於_cellId
類型 謝謝。
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.