[英]How to set scroll position of UITableView on view's load?
I have a UITableView where I want to hide the header of the first row, unless the user scrolls up ward, then it can be present. 我有一个UITableView,我想在其中隐藏第一行的标题,除非用户向后滚动,否则可以显示它。
My current approach is the following: 我当前的方法如下:
Table.ContentInset = new UIEdgeInsets(-30, 0, 0, 0);
Table.ScrolledToTop += (sender, e) => {
Table.ContentInset = new UIEdgeInsets(0, 0, 0, 0);
};
But this does not work as expected. 但这不能按预期工作。 Thanks for any help.
谢谢你的帮助。
You can use this method: 您可以使用以下方法:
tableView.ScrollToRow (Foundation.NSIndexPath.FromItemSection (0, 0), UITableViewScrollPosition.Top, false);
This is the complete code: 这是完整的代码:
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);
Hope it can help you. 希望它能对您有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.