简体   繁体   English

UITableView setContentOffset在viewDidLoad中不起作用

[英]UITableView setContentOffset not working in viewDidLoad

I'm loading my table from nib file, and in viewDidLoad I can't do anything with the table. 我正在从nib文件加载表格,在viewDidLoad ,表格无法执行任何操作。 I can use table's delegate methods to set the contentOffset, and they work, but it doesn't work in viewDidLoad . 我可以使用表的委托方法来设置contentOffset,它们可以工作,但是在viewDidLoad不起作用。

So is the table even loaded in viewDidLoad ? 那么,表是否甚至被加载到viewDidLoad Probably not. 可能不是。 Any idea how to fix it, or check if the table has loaded? 任何想法如何解决它,或检查表是否已加载? (without subclassing) (无子类)

Thanks! 谢谢!

The table view is loaded in viewDidLoad, but normally there is no data in it yet. 表格视图已加载到viewDidLoad中,但是通常其中没有数据。 Calling reloadData in viewDidLoad will cause the data to be loaded and the rows to be populated. 在viewDidLoad中调用reloadData将导致数据被加载并填充行。

Once there is data in the table, and the contentSize of the table is larger than the bounds.size, the tableview will respond appropriately to setContentOffset. 一旦表中有数据,并且表的contentSize大于bounds.size,则tableview将适当地响应setContentOffset。

I have had the same issue but the solution above didn't work for me. 我遇到了同样的问题,但是上面的解决方案对我不起作用。 It's possible because I am using auto layout or because it's been years since this question was answered. 可能是因为我使用的是自动版式,或者因为距回答这个问题已有好几年了。

What worked for me was using viewDidLayoutSubviews. 对我有用的是使用viewDidLayoutSubviews。 Only then the setOffset worked. 只有这样,setOffset才起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM