表格单元格之间的空间增大

时间:2018-07-24 14:21:56

标签: ios uitableview xamarin

我制作了一个UITableViewController,并在其中以编程方式添加了单元格。我直接在Microsoft网站上使用了有关如何使用Xamarin创建表的代码段:https://docs.microsoft.com/en-us/xamarin/ios/user-interface/controls/tables/populating-a-table-with-data

唯一的问题是,所使用的代码会生成一个表,当您向其中添加单元格时,该表将在每个后续单元格之间创建一个间隔不断增大的间隔:

Table Problem

我的UITableViewController故事板看起来很正常,并且没有任何约束或间距:

Storyboard of the table view

有人对为什么会发生此错误有任何想法吗?

要澄清用于表源文件的代码是:

public class mailSource : UITableViewSource
{
    string[] TableItems;
    string CellIdentifier = "TableCell";

    public mailSource(string[] items)
    {
        TableItems = items;
    }

    public override nint RowsInSection(UITableView tableview, nint section)
    {
        return TableItems.Length;
    }

    public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
    {
        UITableViewCell cell = tableView.DequeueReusableCell(CellIdentifier);
        string item = TableItems[indexPath.Row];

        if (cell == null)
        { cell = new UITableViewCell(UITableViewCellStyle.Default, CellIdentifier); }

        cell.TextLabel.Text = item;

        return cell;
    }
}

视图控制器的代码为:

public partial class mailTableController : UITableViewController
{
    public mailTableController (IntPtr handle) : base (handle)
    {
    }

    public override void ViewDidLoad()
    {
        base.ViewDidLoad();
        table = new UITableView(View.Bounds); // defaults to Plain style
        string[] tableItems = new string[] { "Vegetables", "Fruits", "Flower Buds", "Legumes", "Bulbs", "Tubers", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a" };
        table.Source = new mailSource(tableItems);
        Add(table);
    }
}

0 个答案:

没有答案
相关问题