[英]UITableViewController with static cells: contentSize is {0, 0}
In my project , I am adding a UIView
to UITableView
and adjust the UIView
's frame when the contentOffset
of UITableView
changes so that there is an illusion of a floating view above the tableView
's contents. 在我的项目 ,我增加了UIView
到UITableView
和调整UIView
的帧时的contentOffset
的UITableView
变化,因此,有上述浮动视图的幻觉tableView
的内容。
Users of the library now report that this tequnique does not work when the UITableView
is created with static cells through a storyboard . 现在,该库的用户报告说,当通过情节提要用静态单元格创建UITableView
时,该方法无效。
I did a bit of research on this and found that in particular, the tableView.contentSize
becomes {0, 0} as soon as you call [tableView addSubview:...]
. 我对此进行了一些研究,发现特别是,只要调用[tableView addSubview:...]
, tableView.contentSize
就会变为{0,0} 。
Apparently, this is not a problem with dynamic cells , but with static cells, the contentSize stays {0, 0} until you call [tableView reloadData]
显然,这对于动态单元格不是问题 ,但是对于静态单元格,contentSize 保持为{0,0},直到您调用[tableView reloadData]
Do you have any ideas why the UITableView(Controller) is behaving like this with static cells? 您有任何想法为什么UITableView(Controller)在静态单元格中会表现为这种状态吗? And any ideas how to fix this without calling [tableView reloadData]
? 还有什么想法可以解决此问题而无需调用[tableView reloadData]
?
You are using a UITableViewController
. 您正在使用UITableViewController
。 This means that the view
property of the controller is the table view, and the table view is a bit touchy about adding other views. 这意味着控制器的view
属性是表视图,而表视图在添加其他视图时有些麻烦。
Instead, you can go one of two routes: you can transform the controller into a plain UIViewController
, add a table view and declare and implement the datasource and delegate methods for it. 相反,您可以采用以下两种方法之一:您可以将控制器转换为普通的UIViewController
,添加表视图,并为其声明并实现数据源和委托方法。 Then add your other view to the view
rather than the table view. 然后将其他视图添加到该view
而不是表视图。
You could also try to add the view to the window
. 您也可以尝试将视图添加到window
。 This should work, but maybe you need to tweak the positioning if it should be relative to the visible view. 这应该起作用,但是如果它应该相对于可见视图,则可能需要调整位置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.