【问题标题】:Simple Multi Column Table Using Xamarin使用 Xamarin 的简单多列表
【发布时间】:2014-04-07 23:38:12
【问题描述】:

我正在尝试创建一个应用程序来存储 Iphone 应用程序的表数据。

我的桌子是这样的

Header1 Header2 Header3
Row1_1  Row1_2  Row1_3
Row2_1  Row2_2  Row2_3

哪个是 Xamarin 中最容易使用的控制器? 我见过http://docs.xamarin.com/guides/ios/user_interface/tables/part_1_-_table_parts_and_functionality/

但它不支持多列?

我只需要一个简单的表格,单元格中没有图像,也没有交互,只显示简单的数据。

【问题讨论】:

    标签: ios xamarin.ios


    【解决方案1】:

    我最终做的是。我用我的数据动态创建了一个带有表格的简单 HTML,并使用 WebView 从 Xamarin.Forms 或来自 monotouch 的 UIWebview 呈现它并设置其 HTML 源

    WebView view= new WebView();
    string html= @"
    <table style="width:300px">
    <tr>
      <td>Jill</td>
      <td>Smith</td> 
      <td>50</td>
    </tr>
    </table>
    ";
    
    view.Source = new HtmlWebViewSource { Html = html };
    

    【讨论】:

      【解决方案2】:

      开箱即用的 iOS 没有任何出色的网格控件。

      您可以尝试使用自定义 UITableViewCell 来创建多列布局,或者创建自定义 UIView 来执行此操作。 Xamarin 的Component Store 提供了许多网格组件(免费和商业)(搜索“网格”)。您也许还可以找到执行所需操作的本机 iOS 组件或库,并为其创建一个 binding 以允许您在 Xamarin 中使用。

      【讨论】:

        【解决方案3】:

        iOS 中没有网格之类的东西,你需要做的是:

        1. 子类 a UITableViewCell
        2. 每个UITableViewCell 联系一个名为 ContentView 的UIView
        3. 然后您可以根据您的设计位置向 ContentView 添加控件。
        4. 覆盖其 LayoutSubview 方法,并为添加到 ContentView 中的控件设置框架。
        5. 是的,通过覆盖子类UITableViewDelegateGetHeightForRow() 方法来设置/增加行的高度。

        希望这会有所帮助。

        【讨论】:

          【解决方案4】:
          【解决方案5】:

          TechGirl 提出的解决方案其实很简单。

          这里它与 MvvmCross 一起工作。对于纯 iOS,继承自 UITableViewCell 而不是 MvxTableViewCell。

          您可以使用任何控件而不是标签。

          它仍然需要更多的工作(选择一行隐藏文本) - 但我会在忘记之前发布它。

          public class ViewCell : MvxTableViewCell
          {
              UILabel label1;
              UILabel label2;
          
              public ViewCell(IntPtr handle) : base(handle)
              {
                  label1 = new UILabel(new RectangleF(10, 50, 150, 40));
                  label1.Text = "Label 1";
                  this.Add(label1);
                  label2 = new UILabel(new RectangleF(150, 50, 440, 40));
                  label2.Text = "Label 2";
                  this.Add(label2);
          
                  this.DelayBind(() =>
                  {
                      var set = this.CreateBindingSet<ViewCell, SomeType>();
                      set.Bind(label1).To(te => SomeType.ID);
                      set.Bind(label2).To(te => Sometype.Name);
                      set.Apply();
                  });
              }
          
              public override void LayoutSubviews()
              {
                  base.LayoutSubviews();
              }
          }
          

          【讨论】:

            猜你喜欢
            • 2018-07-05
            • 1970-01-01
            • 1970-01-01
            • 2016-12-08
            • 1970-01-01
            • 2021-08-06
            • 2013-02-10
            • 2022-01-17
            • 1970-01-01
            相关资源
            最近更新 更多