【问题标题】:How to create a table with multiple columns in ios如何在ios中创建具有多列的表
【发布时间】:2018-11-03 12:38:10
【问题描述】:

我是 xamarin ios 的初学者,我想创建一个包含 3 列和多行的表,行数取决于来自 API 的数据。我该怎么做...

请帮帮我...

我想创建这样的表...

【问题讨论】:

  • 您需要使用 UICollectionView 并根据输入视图源的数据对其进行配置

标签: c# xamarin.ios storyboard viewcontroller tablelayout


【解决方案1】:

您可以按照以下步骤模拟绘制图表。

  1. 自定义TableHeaderView带有三个黑色矩形,只需添加三个带有黑色边框的标签。

  2. TableViewCell做与步骤1相同的工作,然后在第一个矩形中放置一个文本字段,在第二个矩形中放置一个按钮和一个标签,在第三个矩形中放置两个按钮。

示例代码

TableHeaderView

public class headerView : UIView
{
    public headerView()
    {
        this.Frame = new CGRect(0, 0, UIScreen.MainScreen.Bounds.Width, 50);

        nfloat width = UIScreen.MainScreen.Bounds.Width / 3;

        UILabel title = new UILabel();
        title.Text = "Title";
        title.TextColor = UIColor.Black;
        title.TextAlignment = UITextAlignment.Center;
        title.Font = UIFont.SystemFontOfSize(20);
        title.Layer.BorderColor = UIColor.Black.CGColor;
        title.Layer.BorderWidth = 1;
        title.Frame = new CGRect(0, 0, width, 50);
        this.Add(title);

        UILabel File = new UILabel();
        File.Text = "File";
        File.TextColor = UIColor.Black;
        File.TextAlignment = UITextAlignment.Center;
        File.Font = UIFont.SystemFontOfSize(20);
        File.Layer.BorderColor = UIColor.Black.CGColor;
        File.Layer.BorderWidth = 1;
        File.Frame = new CGRect(width, 0, UIScreen.MainScreen.Bounds.Width / 3, 50);
        this.Add(File);

        UILabel Option = new UILabel();
        Option.Text = "Option";
        Option.TextColor = UIColor.Black;
        Option.TextAlignment = UITextAlignment.Center;
        Option.Font = UIFont.SystemFontOfSize(20);
        Option.Layer.BorderColor = UIColor.Black.CGColor;
        Option.Layer.BorderWidth = 1;
        Option.Frame = new CGRect(width * 2, 0, UIScreen.MainScreen.Bounds.Width / 3, 50);
        this.Add(Option);
    }
}

table.TableHeaderView = new headerView();

TableViewCell

public CustomVegeCell (NSString cellId) : base (UITableViewCellStyle.Default, cellId)
    {
        SelectionStyle = UITableViewCellSelectionStyle.Gray;

        nfloat width = UIScreen.MainScreen.Bounds.Width / 3;

        UIView headingLabel = new UIView();
        headingLabel.Layer.BorderColor = UIColor.Black.CGColor;
        headingLabel.Layer.BorderWidth = 1;
        headingLabel.Frame = new CGRect(0, 0, width, 100);


        UIView subheadingLabel = new UIView();
        subheadingLabel.Layer.BorderColor = UIColor.Black.CGColor;
        subheadingLabel.Layer.BorderWidth = 1;
        subheadingLabel.Frame = new CGRect(width, 0, width, 100);

        UIView imageView = new UIView();
        imageView.Layer.BorderColor = UIColor.Black.CGColor;
        imageView.Layer.BorderWidth = 1;
        imageView.Frame = new CGRect(width *2, 0, width, 100);

        ContentView.Add (headingLabel);
        ContentView.Add (subheadingLabel);
        ContentView.Add (imageView);

        ///add additional control here
    }

    

【讨论】:

  • @Xia-MSFT 我想在单击加号按钮时添加行并在单击减号按钮时删除指定行..,我该怎么做。
  • @AswathyKR 又是一个问题,能开个新帖吗?可以帮助别人搜索。
  • @Xia-MSFT 好的,我添加了一个新线程,你能帮我解决我的问题吗..stackoverflow.com/questions/50814633/…
猜你喜欢
  • 2015-06-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-05-22
  • 2021-07-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多