简体   繁体   English

cellForRowAtIndexPath永远不会被调用,但是numberOfRowsInSection是

[英]cellForRowAtIndexPath never gets called, but numberOfRowsInSection is

I have a viewController with a tableView outlet, and the controller is the dataSource of the tableView . 我有一个带tableView插座的viewController ,控制器是tableViewdataSource

When I tried to reload the tableView using tableView.reloadData() , the dataSource method numberOfRowsInSection is called, and in the console I could see that the numberOfRows is 1 in both section 0 and section 1. However, the cellForRowAtIndexPath is not called. 当我尝试使用tableView.reloadData()重新加载tableView ,调用了dataSource方法numberOfRowsInSection ,并且在控制台中,我可以看到在第0节和第1节中numberOfRows为1。但是,未调用cellForRowAtIndexPath (I put a breakpoint in cellForRowAtIndexPath ). (我在cellForRowAtIndexPath设置了一个断点)。

BTW, cellForRowAtIndexPath did get called once when the controller is first loaded. 顺便说一句,当第一次加载控制器时, cellForRowAtIndexPath确实被调用了一次。

Can anyone please point me the right direction to look at? 谁能给我指出正确的方向吗? been stucked for a while already... 已经被卡住了一段时间了...

I'm using swift 2.0 我正在使用Swift 2.0

Thanks! 谢谢!

Could you please ensure that tableView.reloadData() is being called on main thread. 您能否确保在主线程上正在调用tableView.reloadData() If you are already doing this then check that the UITableView instance you called reloadData on is the same UITableView that you have displayed in your view. 如果已经在执行此操作,请检查调用reloadDataUITableView实例是否与视图中显示的UITableView相同。 This is a common cause for numberOfRowsInSection getting called but not cellForRowAtIndexPath . 这是导致numberOfRowsInSection被调用而不是cellForRowAtIndexPath的常见原因。

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

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