【问题标题】:MonoTouch--Add Button At End of Dynamically Changing TableMonoTouch--在动态变化的表格末尾添加按钮
【发布时间】:2013-06-20 18:02:01
【问题描述】:

我有兴趣在动态变化的表格末尾添加一个按钮。该表格在单击按钮时添加了单元格,但我希望该按钮仅在表格底部滚动到时才可见。我很想知道是否有任何关于如何解决这个问题的想法。

【问题讨论】:

    标签: c# ios xamarin.ios xamarin


    【解决方案1】:

    UIButton 制作UIView 并将其放入FooterView 怎么样?

    tableView.TableFooterView = MyView;
    

    其他解决方案是在数据单元格后添加带有按钮的UITableViewCell。这应该由UITableViewSource 完成。将所有包含最后一个单元格的逻辑移动到抽象类是很好的,它将处理最后一个单元格的功能。

    制作自己的abstract子类UITableViewSource(命名为UITableViewSourceWithFooter),其中将包含:

    • UITableViewCell 带按钮;
    • 方法bool IsLastCellIndexPath(NSIndexPath ip),如果last cellNSIndexPath 参数可见,则返回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;
         } 
    

    【讨论】:

    • 谢谢,这一定是我在 StackOverflow 上收到的最好的答案之一!!
    猜你喜欢
    • 1970-01-01
    • 2019-06-07
    • 1970-01-01
    • 1970-01-01
    • 2010-11-11
    • 2011-01-27
    • 2020-11-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多