【问题标题】:Binding to TableView Xamarin绑定到 TableView Xamarin
【发布时间】:2014-05-29 03:25:55
【问题描述】:

我正在尝试使用以下内容通过 Xamarin ios 绑定到 TableView,但我运气不佳如您所见,我正在使用 parse.com 作为我的数据分析器

  var query = from gaemPlayer in ParseObject.GetQuery ("players")
           select gaemPlayer;
  myPlayers.DataSource = query;

myPlayers 是表源我在 iOS 设计器中给出的名称是 c# 我通常会使用 ToList 函数来创建通用列表,而 Xamarin 则不是这样。

【问题讨论】:

    标签: xamarin.ios xamarin


    【解决方案1】:

    您的来源需要是从 UITableViewSource 派生的类。源类将具有确定表中有多少节和每个节的行的方法,以及实际构建要显示的 UITableViewCell 的方法。您可以覆盖其他方法以获取其他功能,但这些是最低限度的。

    请注意,不能只使用 List 作为 Source 的原因是 Xamarin 正在对 Obj-C UITableView 模式进行建模。构建简单表的另一种方法是使用MonoTouch.Dialog

    public class MySource : UITableViewSource
    {
      private List<item> data;
    
      public MySource(List<Item> data) {
        this.data = data;
      }
    
      public override int RowsInSection (UITableView tableview, int section)
      {
        return data.Count();
      }
    
      public override int NumberOfSections (UITableView tableView)
      {
        return 1;
      }
    
    
      public override UITableViewCell GetCell (UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath)
      {
        // instantiate and return your UITableViewCell here
      }
    

    【讨论】:

    • 我在单元格和 uimage 视图中有一个标签,从我看到的 getCell 方法将是我访问这些属性的地方,我是对的
    • 是的,您实例化一个单元格并在 GetCell 中设置它的属性
    猜你喜欢
    • 1970-01-01
    • 2023-03-12
    • 1970-01-01
    • 1970-01-01
    • 2021-10-16
    • 1970-01-01
    • 2021-08-17
    • 2019-03-14
    • 2021-03-11
    相关资源
    最近更新 更多