简体   繁体   English

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

[英]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.

相关问题 如何在iOS中将UITableView的滚动位置设置为上一个Position - how to set UITableView's scroll position to previous Position in ios 单击“加载较早的项目”按钮时如何将UITableView的滚动位置设置为先前的位置 - how to set UITableView's scroll position to previous location when click “load earlier items” button 将UIPickerView设置为UITableview的底部,而不考虑滚动位置 - Set a UIPickerView to bottom of UITableview regardless of scroll position 如何保存 Flutter 自定义滚动视图的滚动位置? - How to save Flutter Custom Scroll View's scroll position? 如何在视图中更改UITableView的位置? - How to change the position of an UITableView in a View? 如何实时获取UITableView的滚动位置 - How to get the scroll position of a UITableView in real time UITableview向上或向下滚动时崩溃以及如何为每个单元格设置水平滚动视图 - UITableview Crash when scroll up or down and how to set horizontal scroll view to every cell 恢复滚动位置uitableview - restore scroll position uitableview 记住UITableView上的滚动位置 - Remembering scroll position on UITableView UITableView -> 如何在向下滚动时加载附加条目? - UITableView -> How to load additional entry on scroll down?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM