Ios 重用UITableViewCell不会';行不通
我使用的是MonoTouch,我有一个自定义的单元视图,不能重复使用Ios 重用UITableViewCell不会';行不通,ios,uitableview,xamarin.ios,Ios,Uitableview,Xamarin.ios,我使用的是MonoTouch,我有一个自定义的单元视图,不能重复使用 我已尝试设置IBUIReuseIdentifier 我已经尝试将string和NSString用于\u cellId类型 我已尝试重新创建该项目 有趣的是,我有其他自定义单元格,它们工作正常,但我创建的任何新单元格都没有得到重用。我不确定下一步该去哪里 谢谢 public override UITableViewCell GetCell (UITableView tableView,
NSString
用于\u 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接口,我真的建议你阅读这篇文章
希望有帮助。一些注意事项
您是否为每个单元使用控制器
那么,您在哪里声明了cellId
最后,注意cell.Tag=Environment.TickCount代码>Environment.TickCount调用可能会导致问题,因为它的速度足以创建相等的标记
说到这里,我认为你不需要为每个单元都安装控制器(如果你使用的话)。您可以创建一个扩展UITableViewCell
的自定义类,并按原样使用它。如果你使用xib接口,我真的建议你阅读这篇文章
希望有帮助。您没有显示实际创建单元格的代码-创建新单元格时是否使用_cellId作为标识符?如果没有,则DequeueReusableCell()将永远找不到匹配的单元格,并且将始终导致您创建新的单元格。您没有显示实际创建单元格的代码-创建新单元格时是否使用_cellId作为标识符?如果您没有,那么DequeueReusableCell()将永远找不到匹配的单元格,并且将始终导致您创建一个新的单元格。