【发布时间】:2013-06-20 18:02:01
【问题描述】:
我有兴趣在动态变化的表格末尾添加一个按钮。该表格在单击按钮时添加了单元格,但我希望该按钮仅在表格底部滚动到时才可见。我很想知道是否有任何关于如何解决这个问题的想法。
【问题讨论】:
标签: c# ios xamarin.ios xamarin
我有兴趣在动态变化的表格末尾添加一个按钮。该表格在单击按钮时添加了单元格,但我希望该按钮仅在表格底部滚动到时才可见。我很想知道是否有任何关于如何解决这个问题的想法。
【问题讨论】:
标签: c# ios xamarin.ios xamarin
用UIButton 制作UIView 并将其放入FooterView 怎么样?
tableView.TableFooterView = MyView;
其他解决方案是在数据单元格后添加带有按钮的UITableViewCell。这应该由UITableViewSource 完成。将所有包含最后一个单元格的逻辑移动到抽象类是很好的,它将处理最后一个单元格的功能。
制作自己的abstract子类UITableViewSource(命名为UITableViewSourceWithFooter),其中将包含:
UITableViewCell 带按钮;bool IsLastCellIndexPath(NSIndexPath ip),如果last cell 对NSIndexPath 参数可见,则返回true。代码: protected bool IsLastCellIndexPath(NSIndexPath ip)
{
return ip.Row == GetRecordsCount();
}
GetRecordsCount(),RowsInSection 方法。 Sealed 避免在子类中覆盖。他们将改为实现GetRecordsCount() 方法: public sealed override int RowsInSection (UITableView tableview, int section)
{
return GetRecordsCount() + 1;
}
然后实现并使用UITableViewSourceWithFooter的子类:
GetCell 中做一些逻辑: if (base.IsLastCellIndexPath(indexPath) {
return base.cell_with_button;
} else {
return data_cell;
}
GetRecordsCount()。简单来说就是: List<item_class> items;
...
protected override GetRecordsCount()
{
return items.Count;
}
【讨论】: