我正在从 firebase 下载数据并将数据显示到 tableView 上。但是,我发现我的 tableView 中时不时出现重复的内容。我最初以为我不小心在我的 PostService.ps.posts 数组中插入了相同的内容。但是,在我在重新加载 tableView 之前放置一个断点之后,我在控制台中键入了以下命令,但输出很奇怪。
print PostService.ps.posts
如下面的输出所示,item [4] 和 item [6] 有 {...} 我不知道它们代表什么(这是我第一次使用控制台命令进行调试)。在我的 tableView 中。我看到数据按以下顺序显示 [1]、[2]、[3]、[3]、[5]、[5]、[6]、[7]、[8]、[9](对于第 0 行到第 8 行)。所以看起来第 3 行(从 0 开始)获得与第 2 行相同的数据,第 5 行获得与第 4 行相同的数据。奇怪吗?
我不确定为什么会发生这种情况,而且我也无从下手,因为这种情况并非每次都会发生。我希望这个控制台输出能帮助我找到正确的方法
[1] = 0x000000012f4849b0 {
_postKey = "-KQTh_WDO2IS1rYfLgnU"
_userId = "SpmZmYwD3Td04sQZxOYeALwuMp03"
}
[2] = 0x0000000130e61f40 {
_postKey = "-KQTHnE4IIeBR3tyDM3r"
_userId = "1isMS98ZmXYrpCmGb4o5voaAqXH2"
_image = "www.image2.com"
}
[3] = 0x0000000130192b40 {
_postKey = "-KQtN4YG51HOF19FrM8s"
_userId = "SpmZmYwD3Td04sQZxOYeALwuMp03"
_image = "www.image3.com"
}
[4] = 0x0000000130192b40 {...}
[5] = 0x0000000130269560 {
_postKey = "-KR2On6u7dRy0GAvE1Gn"
_userId = "SpmZmYwD3Td04sQZxOYeALwuMp03"
_image = "www.image4.com"
}
[6] = 0x0000000130269560 {...}
[7] = 0x000000013150f4c0 {
_postKey = "-KQThGLVA-MsviGMsXOS"
_userId = "1isMS98ZmXYrpCmGb4o5voaAqXH2"
_image = "www.image5.com"
}
[8] = 0x000000012fa88890 {
_postKey = "-KQt269uHGM99oFKuJRt"
_userId = "SpmZmYwD3Td04sQZxOYeALwuMp03"
_image = "www.image6.com"
}
[9] = 0x000000012f9bcad0 {
_postKey = "-KQThdCAm-PlCsCnXcBZ"
_userId = "SpmZmYwD3Td04sQZxOYeALwuMp03"
}
我所有的表数据都是根据我的 PostService.ps.posts 中的数据配置的,它是 [Post] 类型 在我的 viewForHeaderInSection 中(我在我的应用程序中使用它而不是 cellForRowAtIndexPath),我有以下代码来配置表
if let cell = tableView.dequeueReusableHeaderFooterViewWithIdentifier("TableSectionHeader") as? TableSectionHeader {
let post = PostService.ps.posts[section]
var image: UIImage?
if let url = post.imageUrl {
image = DiscoverVC.imageCache.objectForKey(url) as? UIImage
}
cell.configureCell(post, image: image)
cell.delegate = self
return cell
} else {
return TableSectionHeader()
}
最佳答案
好的,我阅读了您的问题,让我帮助您理解您用于打印 PostService.ps.posts
数组元素的命令。
po
command prints the object's "description" method.
尝试在 viewForHeaderInSection
中写入 po PostService.ps.posts[section]
,它将打印 post
类型的对象。
在这里您可以打印post
自定义类对象的所有属性,如下所示:-
现在写 po post.imageUrl
,
po post.postKey
, po post.userId
交叉检查所有标题的所有这些输出。检查这些值是否相同或不同。如果这些值不同,那么问题将出在表格单元格的出列中,否则如果这些值相同,那么问题将出在您的服务器逻辑(后端)中。
关于ios - Xcode控制台调试输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39386367/