使用Xamarin的简单多列表

时间:2014-04-07 23:38:12

标签: ios xamarin.ios

我正在尝试创建一个应用程序来存储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/

但它不支持多列?

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

5 个答案:

答案 0 :(得分:2)

我最终做的是。我使用我的数据动态创建了一个带有表的简单HTML,并使用WebView从单调处理中从Xamarin.Forms或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 };

答案 1 :(得分:1)

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

您可以尝试使用自定义UITableViewCell创建多列布局,或创建自定义UIView来执行此操作。 Xamarin的Component Store(搜索&#39;网格&#39;)提供了许多网格组件(免费和商业)。您也可以找到符合您需要的原生iOS组件或库,并为其创建binding,以便您可以使用Xamarin。

答案 2 :(得分:1)

在iOS中没有像网格那样的东西,你需要做的是:

  1. 子类UITableViewCell
  2. 每个UITableViewCell与名为ContentView的UIView联系
  3. 然后,您可以根据设计位置向ContentView添加控件。
  4. 覆盖其LayoutSubview方法,并为ContentView中添加的控件设置框架。
  5. 是的,通过覆盖子类GetHeightForRow()的{​​{1}}方法来设置/增加行的高度。
  6. 希望这有帮助。

答案 3 :(得分:1)

答案 4 :(得分:0)

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();
    }
}