簡體   English   中英

如何從 TableView 頂部刪除頂部空間?

[英]How to remove top space from Top of TableView?

在我的視圖控制器中,我有 1 個具有不同數據的表視圖。

頂部藍色是視圖,底部藍色是 TabBar。

在主屏幕中有頂部視圖和趨勢屏幕中我通過將其約束更改為 0 來隱藏它。

  1. 家和 2. 趨勢

當我滾動 tableview 以查看新帖子時,當我單擊 Trending View 時,我在 TableView 中加載新數據並將 tableview 滾動到代碼頂部。

dispatch_async(dispatch_get_main_queue(), ^{
        [self.tblVW setContentOffset:CGPointZero animated:NO];
        [self.tblVW reloadData];
    });

但它不會移動到表格視圖的頂部。

頂部有一個空間,當我觸摸 tableview 時,它會滾動到頂部。

分組表視圖中,如果要刪除頂部區域的默認標題,請嘗試設置:

tableView.tableHeaderView = UIView(frame: CGRect(x: 0, y: 0, width: 0, height: 0.1))

分組表視圖:

分組表視圖

前:

前

后:

后

我猜你正在使用分組表視圖。 請制作

self.tblVW.tableHeaderView = [[UIView alloc]initWithFrame:CGRectMake(0,0,0,0.01f)];

甚至將 tableview 部分標題的高度設置為 0.01f。

YourTableView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);

設置上面的代碼。

您需要禁用 automaticallyAdjustsScrollViewInsets 。

添加這一行 ViewDidLoad

self.automaticallyAdjustsScrollViewInsets = false

試試這個將表格視圖滾動到頂部

dispatch_async(dispatch_get_main_queue(), ^{
        [self.tblVW.scrollToRowAtIndexPath(NSIndexPath(forRow: 0,inSection: 0), atScrollPosition: UITableViewScrollPosition.Top, animated: true)];
        [self.tblVW reloadData];
    });

而不是設置內容偏移量。

這對我有用,將此代碼放在 viewDidLoad() tableView.contentInset = UIEdgeInsets(top: -35, left: 0, bottom: 0, right: 0)

例子:

override func viewDidLoad() {
   super.viewDidLoad()
   self.setupTableView() 
}

func setupTableViews() {
   tableView.contentInset = UIEdgeInsets(top: -35, left: 0, bottom: 0, right: 0) 
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM