简体   繁体   English

带有静态单元格的UITableViewController:contentSize为{0,0}

[英]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. 在我的项目 ,我增加了UIViewUITableView和调整UIView的帧时的contentOffsetUITableView变化,因此,有上述浮动视图的幻觉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.

相关问题 带有工具栏的模态UITableViewController(静态单元格) - Modal UITableViewController (static cells) with toolbar 使用静态单元格推送 UITableViewController 时出现断断续续的动画 - Choppy animation while pushing UITableViewController with static cells iOS 5:使用静态单元格和文本字段在UITableViewController中隐藏键盘 - iOS 5: Hide keyboard in UITableViewController with static cells and textfields iOS - 在带有静态单元格的UITableViewController上使用UISearchDisplayController - iOS - Using a UISearchDisplayController on a UITableViewController with static cells UITableViewController中的静态单元格在同一个nib上打开不同的URL - Static cells in UITableViewController opening different URL on the same nib 使用静态UITableViewController创建两个部分,其中第一部分具有非静态单元格数 - Using a static UITableViewController to create two sections with the first section having a non-static number of cells 在UITableViewController中重建表单元格 - rebuild table cells in UITableViewController UITableViewController 之外的静态表格视图 - Static table view outside UITableViewController 嵌套的UITableViewController不显示任何单元格 - Nested UITableViewController does not show any cells 将表格单元格添加到 inhiret UITableViewController 的类中 - add table cells to class that inhiret UITableViewController
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM