ios - cellForRowAtIndexPath 被调用两次

标签 ios uitableview ios7

我正在显示通过 Storyboard 初始化的动态表格 View 。
没什么特别的,只是用文本标签初始化 3 个单元格。

以下是实际发生的情况:

2014-08-15 12:39:19.909 PopTestAnimation[31825:60b] numberOfSectionsInTableView
2014-08-15 12:39:19.926 PopTestAnimation[31825:60b] numberOfSectionsInTableView
2014-08-15 12:39:19.927 PopTestAnimation[31825:60b] numberOfRowsInSection
2014-08-15 12:39:19.929 PopTestAnimation[31825:60b] cellForRowAtIndexPath: 0
2014-08-15 12:39:19.943 PopTestAnimation[31825:60b] Displaying row: 0
2014-08-15 12:39:19.943 PopTestAnimation[31825:60b] cellForRowAtIndexPath: 1
2014-08-15 12:39:19.945 PopTestAnimation[31825:60b] Displaying row: 1
2014-08-15 12:39:19.945 PopTestAnimation[31825:60b] cellForRowAtIndexPath: 2
2014-08-15 12:39:19.946 PopTestAnimation[31825:60b] Displaying row: 2
2014-08-15 12:39:19.947 PopTestAnimation[31825:60b] numberOfSectionsInTableView
2014-08-15 12:39:19.947 PopTestAnimation[31825:60b] numberOfRowsInSection
2014-08-15 12:39:19.948 PopTestAnimation[31825:60b] cellForRowAtIndexPath: 0
2014-08-15 12:39:19.949 PopTestAnimation[31825:60b] Displaying row: 0
2014-08-15 12:39:19.949 PopTestAnimation[31825:60b] cellForRowAtIndexPath: 1
2014-08-15 12:39:19.950 PopTestAnimation[31825:60b] Displaying row: 1
2014-08-15 12:39:19.951 PopTestAnimation[31825:60b] cellForRowAtIndexPath: 2
2014-08-15 12:39:19.952 PopTestAnimation[31825:60b] Displaying row: 2

由于某种原因,似乎每个单元格都被初始化了两次。任何想法为什么?

这里是 code

最佳答案

我刚刚检查了 Storyboard文件。在 TraffleViewController(UITableViewController 的子类)的 Storyboard中,您有一个 UITableViewWrapper 和另一个 UITableView。
里面应该只有一个 UITableViewWrapper 而没有其他 UITableView。由于 UITableViewWrapper 中有一个 UITableView ,因此有两个调用:

cellForRowAtIndexPath:
如果您进行调试并在其中打印 UITableView 的实例:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
你会发现两个独立的 UITableView 实例。
请按照以下步骤解决。

1.Remove the view called "Table View" from storyboard.

2.Drag a UITableView inside TraffleViewController

3.Set the datasource and delegate of UITableView to TraffleViewController.

关于ios - cellForRowAtIndexPath 被调用两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25333181/

相关文章:

ios - iOS7 上的 NSFileManager 无限循环

ios - dismissViewControllerAnimated() 不会关闭 View Controller

ios - Array.contains(其中 :) to return Array item that returned true

objective-c - 在具有滚动索引的 UITableView 中延迟加载图像

objective-c - 检查 SKNode 是否在屏幕上且可见

ios - 是否可以在 iPhone 响铃时打开 iPhone 应用程序或在 iPhone 响铃时更改其状态?

iphone - 如何检查为什么 viewWillDisappear : is called

ios - iOS 8 横向纵向模式下的自定义键盘

ios - 类型 'UITableViewCell' 的值没有成员

objective-c - 如何对表的数据进行排序 按部分的字母顺序查看