简体   繁体   English

正在回答自己-uitableview-iOS7-未调用cellForRowAtIndexPath

[英]ANnswering myself - uitableview - ios7 - cellForRowAtIndexPath not called

I am using a uivewcontroller with an embedded uitableview created using storyboard. 我正在使用带有使用情节提要创建的嵌入式uitableview的uivewcontroller。

The tableview was set to use my custom view controller. tableview设置为使用我的自定义视图控制器。

It was set to have "dynamic prototypes". 它被设置为具有“动态原型”。

The cell had the reuse identifier correctly set. 单元具有正确设置的重用标识符。

I didn't need to register cell reuse identifier for my cell manually as it was created using storyboard. 我不需要手动为单元格注册单元重用标识符,因为它是使用情节提要创建的。 But I still tried. 但是我仍然尝试。

Table view was also set correctly to use my custom view controller for datasource and delegate (which a lot of SO posts talked about). 表格视图也已正确设置为使用我的自定义视图控制器进行数据源和委托(很多SO帖子都在讨论)。 I also added an outlet to my tableview in my view controller and manually called [mytableview2.delegate=self; [mytableview2.dataSource=self; 我还在视图控制器的表视图中添加了一个出口,并手动调用了[mytableview2.delegate=self; [mytableview2.dataSource=self; [mytableview2.delegate=self; [mytableview2.dataSource=self; Still no luck. 仍然没有运气。

I was loading the data into the array before my tableview numberofrowsinsection was called, so that wasn't the issue. 在调用tableview numberofrowsinsection之前,我正在将数据加载到数组中,所以这不是问题。

I also tried adding [mytableview reloadData] statements after loading the data in the viewDidLoad method. 我还尝试在viewDidLoad方法中加载数据后添加[mytableview reloadData]语句。 No dice. 没有骰子。

Cell height was set to 120 (not zero as was the case in some other SO posts). 像元高度设置为120(在其他一些SO帖子中不是零)。

I also changed the background color of my view, table view and cells to different colors (gray, yellow, red). 我还将视图,表格视图和单元格的背景颜色更改为不同的颜色(灰色,黄色,红色)。 But all I would see in simulator was gray. 但是我在模拟器中看到的只是灰色。 So tableview and cell wasn't even shown. 因此,甚至没有显示tableview和单元格。

To debug, I put NSLog and break points at the " numberofrowsinsection ", " numberofsections " and " Cellforrowatindexpath ". 为了调试,我将NSLog和断点放在“ numberofrowsinsection ”,“ numberofsections ”和“ Cellforrowatindexpath ”处。

The numberofrowsinsection, numberofsections were called and confirmed that my array was not empty. 调用了numberofrowsinsection,numberofsections并确认我的数组不为空。 They returned positive counts. 他们返回了正数。 But my cellforrowatindexpath never got called . 但是我的cellforrowatindexpath从未被调用过

After pulling my hair for couple hours, I found the issue. 拉了几个小时的头发后,我发现了问题。

I had used Xcode's storyboard autolayout option "Add missing constraints" to automatically add constraints to my table view. 我曾使用Xcode的情节提要自动布局选项“添加缺少的约束”将约束自动添加到表视图中。 This was the issue! 这就是问题! As soon as I deleted all the constraints, my tableview cells apppeared right away!! 一旦删除所有约束,我的tableview单元就会立即消失! I didn't find this in any of the SO posts, so hope this helps someone else! 我在任何SO帖子中都没有找到这个,所以希望这对其他人有帮助! So if you face a similar issue and have confirmed everything above is setup correctly, then try deleting all the constraints on your tableview! 因此,如果您遇到类似的问题并确认以上所有设置均正确设置,请尝试删除表视图上的所有约束!

I had used Xcode's storyboard autolayout option "Add missing constraints" to automatically add constraints to my table view. 我曾使用Xcode的情节提要自动布局选项“添加缺少的约束”将约束自动添加到表视图中。 This was the issue! 这就是问题! As soon as I deleted all the constraints, my tableview cells apppeared right away!! 一旦删除所有约束,我的tableview单元就会立即消失! I didn't find this in any of the SO posts, so hope this helps someone else! 我在任何SO帖子中都没有找到这个,所以希望这对其他人有帮助! So if you face a similar issue and have confirmed everything above is setup correctly, then try deleting all the constraints on your tableview and testing! 因此,如果您遇到类似的问题并确认以上所有设置均正确设置,请尝试删除表视图上的所有约束并进行测试! Then manually adding constraints one by one correctly manually. 然后手动正确地手动一个接一个地添加约束。

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

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