![](/img/trans.png)
[英]How to remove extra space from the top and bottom of the UITextview in iOS?
[英]How to remove top space from Top of TableView?
在我的視圖控制器中,我有 1 個具有不同數據的表視圖。
頂部藍色是視圖,底部藍色是 TabBar。
在主屏幕中有頂部視圖和趨勢屏幕中我通過將其約束更改為 0 來隱藏它。
當我滾動 tableview 以查看新帖子時,當我單擊 Trending View 時,我在 TableView 中加載新數據並將 tableview 滾動到代碼頂部。
dispatch_async(dispatch_get_main_queue(), ^{
[self.tblVW setContentOffset:CGPointZero animated:NO];
[self.tblVW reloadData];
});
但它不會移動到表格視圖的頂部。
頂部有一個空間,當我觸摸 tableview 時,它會滾動到頂部。
我猜你正在使用分組表視圖。 請制作
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.