简体   繁体   English

如何定位UITableView(MonoTouch)

[英]How to position UITableView (MonoTouch)

Given the following code: 给出以下代码:

public class MainTableController : UITableViewController
{
    // Allow us to set the style of the TableView
    public MainTableController(UITableViewStyle style) : base(style)
    {
    }

    public override void ViewDidLoad ()
    {   
        TableView.DataSource = new MainTableDataSource();
        TableView.Delegate = new MainTableDelegate(this);

        TableView.BackgroundColor = UIColor.FromPatternImage(UIImage.FromFile ("Content/Background-Home@2x.png"));

        TableView.Bounces = false;

        base.ViewDidLoad ();
    }
}

Given the following output: 给出以下输出:

在此处输入图片说明

How can I update my code so that the group of table cells starts halfway down the page? 如何更新我的代码,以使表格单元格组从页面的一半开始? The actual pixels aren't important, I am just trying to figure out where properties are to modify this. 实际的像素并不重要,我只是想弄清楚属性在哪里进行修改。

It's not a good idea to manually position the UITableView in a UITableViewController. 手动将UITableView放置在UITableViewController中不是一个好主意。 That being said I think adjusting the ContentInset property should get you where you need to go: 话虽这么说,我认为调整ContentInset属性应该可以让您到达需要的位置:

this.TableView.ContentInset = new UIEdgeInsets(this.TableView.Center.Y, 0, 0, 0);

This should push down the first Section / Cell to the specified UIEdgeInset.Top value. 这应该将第一个Section / Cell下推到指定的UIEdgeInset.Top值。

Edit: As per clarification in comments... 编辑:根据注释中的说明...

If you need to maintain position of the background view...you might have better luck by creating a HeaderView for the first section and increasing it's frame to a size sufficient enough to move the first cell down: 如果您需要保持背景视图的位置...通过为第一部分创建HeaderView并将其框架增大到足以将第一个单元格向下移动的大小,可能会更好。

public override UIView GetViewForHeader (UITableView tableView, int sectionIdx)
{
    if(sectionIdx == 0) { 

        // adjust appropriate index above ^

        var view = new UIView();
        view.Frame = new RectangleF(...) // adjust your frame here
        return view;    
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM