簡體   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