重用UITableViewCell不起作用

时间:2012-06-01 21:21:09

标签: ios uitableview xamarin.ios

我正在使用MonoTouch,我有一个自定义的单元格视图,但没有被重用。

  1. 我尝试过设置IBUIReuseIdentifier
  2. 我尝试使用字符串NSString作为_cellId类型
  3. 我尝试重新创建项目。
  4. 有趣的是,我有其他自定义单元格正常工作但我创建的任何新单元格都没有被重用。我不确定下一步该去哪看。
  5. 感谢。

    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;
    }
    

1 个答案:

答案 0 :(得分:1)

一些笔记

您是否为每个细胞使用控制器?

然后,你在哪里宣布_cellId

最后,请注意cell.Tag = Environment.TickCount;Environment.TickCount调用可能会导致问题,因为它可能足够快以创建相同的标记。

说这个,我认为你并不需要一个控制器(如果你使用它)为每个单元格。您可以创建一个扩展UITableViewCell的自定义类,并按原样使用它。如果您使用xib界面,我建议您阅读帖子creating-custom-uitableviewcells-with-monotouch-the-correct-way

希望它有所帮助。

相关问题