繁体   English   中英

如何在视图的负载上设置UITableView的滚动位置?

[英]How to set scroll position of UITableView on view's load?

我有一个UITableView,我想在其中隐藏第一行的标题,除非用户向后滚动,否则可以显示它。

我当前的方法如下:

Table.ContentInset = new UIEdgeInsets(-30, 0, 0, 0);
Table.ScrolledToTop += (sender, e) => {
        Table.ContentInset = new UIEdgeInsets(0, 0, 0, 0);

};

但这不能按预期工作。 谢谢你的帮助。

您可以使用以下方法:

tableView.ScrollToRow (Foundation.NSIndexPath.FromItemSection (0, 0), UITableViewScrollPosition.Top, false);

这是完整的代码:

tableView = new UITableView (UIScreen.MainScreen.Bounds);
            this.View.AddSubview (tableView);

            UILabel header = new UILabel (new CGRect (0, 0, tableView.Frame.Width, 50)){BackgroundColor = UIColor.Blue};
            header.Text = "I'm header";
            header.TextColor = UIColor.White;
            header.TextAlignment = UITextAlignment.Center;
            tableView.TableHeaderView = header;

            TableViewSource mySource = new TableViewSource ();
            tableView.Source = mySource;
            tableView.ReloadData ();

            tableView.ScrollToRow (Foundation.NSIndexPath.FromItemSection (0, 0), UITableViewScrollPosition.Top, false);

希望它能对您有所帮助。

暂无
暂无

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

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