coj*_*joj 63 objective-c uitableview uiscrollview ios pull-to-refresh
在我的应用程序中,我有一个UISearchBarunder,UINavigationBar因此它始终对用户可见.在这种情况下,我必须设置contentInset额外的44px,因此UIScrollView将滚动UISearchBar (完全像在Contacts.app中).静态UITableView的没有问题,但在我的情况下,我必须重新加载它的内容,切换到UISearchDisplayController等等.所以当我打电话时:
[self.tableView setContentInset:UIEdgeInsetsMake(108, 0, 0, 0)];
Run Code Online (Sandbox Code Playgroud)
一切都有效,直到我拉动刷新......(为此我使用SSPullToRefresh).
所以我的问题是:如何contentInset永久设置,以便我不必担心内部数据发生任何变化UITableView?
coj*_*joj 187
可能这是我的错误,因为我搞乱了自动布局和故事板,但我找到了答案.
你必须在View Controller的 Attribute Inspector中
照顾这个小家伙
必须取消选中它才能contentInset在任何更改后设置默认值.之后,它只是添加一个班轮viewDidLoad:
[self.tableView setContentInset:UIEdgeInsetsMake(108, 0, 0, 0)]; // 108 is only example
Run Code Online (Sandbox Code Playgroud)
iOS 11,Xcode 9更新
看起来像以前的解决方案不再是一个正确的解决方案,如果它涉及到iOS 11和Xcode 9.automaticallyAdjustsScrollViewInsets已被弃用,现在为了达到类似的效果你必须去大小检查器,你可以在这里找到:

此外,您可以在代码中实现相同的功能:
if #available(iOS 11.0, *) {
scrollView.contentInsetAdjustmentBehavior = .never
} else {
automaticallyAdjustsScrollViewInsets = false
}
Run Code Online (Sandbox Code Playgroud)
rmo*_*ney 69
在Swift中:
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
self.tableView.contentInset = UIEdgeInsets(top: 108, left: 0, bottom: 0, right: 0)
}
Run Code Online (Sandbox Code Playgroud)
iOS11中不推荐使用automaticAdjustsScrollViewInsets(并且已接受的解决方案不再有效).使用:
if #available(iOS 11.0, *) {
scrollView.contentInsetAdjustmentBehavior = .never
} else {
automaticallyAdjustsScrollViewInsets = false
}
Run Code Online (Sandbox Code Playgroud)
在numberOfRowsInSection中添加您的代码[self.tableView setContentInset:UIEdgeInsetsMake(108, 0, 0, 0)];。因此,您将始终在表中重新加载数据时设置contentInset
| 归档时间: |
|
| 查看次数: |
116516 次 |
| 最近记录: |