如何定位UITableView(MonoTouch)

时间:2011-12-04 00:25:52

标签: iphone xamarin.ios uitableview

给出以下代码:

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

给出以下输出:

enter image description here

如何更新我的代码,以便表格单元格组在页面中间开始?实际的像素并不重要,我只想弄清楚属性在哪里修改它。

1 个答案:

答案 0 :(得分:3)

在UITableViewController中手动定位UITableView并不是一个好主意。话虽如此,我认为调整ContentInset属性可以让你到达目的地:

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

这应该将第一个Section / Cell下推到指定的UIEdgeInset.Top值。

修改:根据评论中的说明......

如果您需要保持背景视图的位置......您可以通过为第一部分创建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;    
    }
}