[英]Monotouch UITableViewCell AddSubView
我正在尝试创建一个类似于视图的表/网格,我可以用它来显示大量信息。
我尝试实现此目的的方法是创建自定义单元格视图。 它基本上是UINavigationController
,我知道这是不正确的,因为它需要是一个UIView
才能将它添加到UITableViewCell.ContentView.AddSubView(UiView view)
。
它看起来像这样:
然后在我的表源GetCell()
我有这个。
public override UITableViewCell GetCell (UITableView tableView, NSIndexPath indexPath)
{
int rowIndex = indexPath.Row;
Incident _incident = tableData[rowIndex];
UITableViewCell cell = tableView.DequeueReusableCell(cellID);
if(cell == null)
cell = new UITableViewCell(UITableViewCellStyle.Default, cellID);
CustomCellView content = new CustomCellView();
content.SetRef(_incident.Id);
content.SetDescription(_incident.Description);
cell.ContentView.Add(content);
return cell;
}
它的cell.ContentView.Add
是我出错的地方? 我只需要将我在IB中创建的自定义视图添加到单元格内容中。
我认为这个答案将帮助您将Xcode / InterfaceBuilder NIB文件与UITableViewCell
。
要记住的一件重要事情是,你(经常) 重新使用细胞,它们将处于你离开它们的状态。
因此,如果您每次重复使用单元格时添加(例如Add
或AddSubview
)并且永远不会删除视图(或子视图...),那么您的内存使用量将随着时间的推移而增长(滚动表格时可能会非常快速地发生)。
我自己想出来了。 我没有继承正确的观点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.