reloadData 被调用两次?

发布于 2024-10-21 02:54:11 字数 1055 浏览 6 评论 0原文

我很长时间以来一直在为我的应用程序查看这段代码。当用户添加 ALBUM 时,会将其添加到 RootViewController 中的数组 (listOfItems) 中。然后不同的类调用它来更新(reloadData)。查看一些 NSLogs 后,它会执行以下操作

  • numberOfRowsInSection 更新多少行(正确)
  • cellForRowAtIndexPath 显示行(NSLog 显示 listOfItems 是正确的)
  • numberOfRowsInSection code> 重复并删除所有新数据
  • cellForRowAtIndexPath 再次重复,它显示除新数据之外的所有内容

我不知道为什么它会重复 - 我只是调用 [self.tableView reloadData];一次。

我检查了所有 NSTimers,我什至让应用程序在那里停留大约一分钟,控制台中什么也没有显示。

请帮忙! Coulton

PS:如果您需要任何代码,请询问!


编辑: 这是一个 NSLog 示例,说明了单元格文本的情况

Number Of Rows: 3
Array: (One, Two, Three)

:一 单元格文本:两个 单元格文本:三

--- 添加“四”单元格 ---

Number of Rows: 4
Array: (One, Two, Three, Four)

Number of Rows: 3
Array: (One, Two, Three)

Cell Text: One
Cell Text: Two
Cell Text: Three

编辑:完整 RootViewContoller.m

REMOVED

PS:抱歉代码太长,但再次感谢!

I have been looking at this code for my app for a long time. When a user adds a ALBUM, it adds it to a array (listOfItems) in the RootViewController. The different class then calls it to update (reloadData). After looking though some NSLogs, it does the following

  • numberOfRowsInSection updates how many rows (correct)
  • cellForRowAtIndexPath displays rows (NSLog shows that the listOfItems is correct)
  • numberOfRowsInSection repeats and deletes all new data
  • cellForRowAtIndexPath repeats yet again, and it shows everything but the new data

I have no idea why it repeats - I am only calling [self.tableView reloadData]; once.

And I have checked all my NSTimers, I even let the app just sit there for about a minute to nothing in console shows up.

Please help!
Coulton

PS: If you need any code, please ask!


Edit: Here's a sample NSLog of what's going on

Number Of Rows: 3
Array: (One, Two, Three)

Cell Text: One
Cell Text: Two
Cell Text: Three

--- Add cell of "Four" ---

Number of Rows: 4
Array: (One, Two, Three, Four)

Number of Rows: 3
Array: (One, Two, Three)

Cell Text: One
Cell Text: Two
Cell Text: Three

Edit: Full RootViewContoller.m

REMOVED

PS: Sorry for the long code but thanks again!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

我一直都在从未离去 2024-10-28 02:54:11

CellForRowAtIndexPath 对表格视图中显示的每个单元格重复,需要有关放置 NSLog 的位置的更多信息。

The CellForRowAtIndexPath repeats for each cell shown in your tableview, more info required regarding where you are placing your NSLogs.

瘫痪情歌 2024-10-28 02:54:11

numberOfRowsInSection 实现中的某处添加断点。当您点击断点时,切换到调试器视图并查看堆栈跟踪。对您接到的两个电话都执行此操作。
在堆栈中向下查找,直到找到属于您的方法(显示为粗体)。您应该能够弄清楚您在哪里调用 reloadData

如果对于断点命中,您找不到自己的任何方法作为调用源,那么也许您确实有一个 NSTimer 或可以为您调用它的东西。

调试愉快:)

Add a breakpoint somewhere in the implementation of numberOfRowsInSection. When you hit the breakpoint switch to the debugger view and look at the stack trace. Do this for both calls that you get.
Look down in the stack until you find methods that belong to you (the appear bolded). You should be able to figure out where you are calling reloadData.

If for a breakpoint hit, you can't find any methods of your own as the source of the call, then maybe you do have a NSTimer or something that calls it for you.

Happy debugging :)

心凉 2024-10-28 02:54:11

不确定这是否有帮助,但如果您的班级中有的话,请尝试在 viewWillAppear 中注释 [super viewWillAppear:animated] 。这似乎是较新版本的 sdk 中的一个错误。

- (void)viewWillAppear:(BOOL)animated {
    //[super viewWillAppear:animated];
}

Not sure if this helps but try to outcomment [super viewWillAppear:animated] in viewWillAppear if you have that in your class. It seems to be a bug in newer versions of the sdk.

- (void)viewWillAppear:(BOOL)animated {
    //[super viewWillAppear:animated];
}
抱着落日 2024-10-28 02:54:11

如果其他人遇到此问题,只需使用 NSTimer 每 X 秒重新加载数据即可。我什至对填充数据的 ARAAY 和表中当前的 ROWS 做了一些计数器,以查看是否有必要更新。如果没有,它就没有任何作用。

If anyone else has this problem, simply use a NSTimer to reload the data every X seconds. I even did a little counter on the ARAAY that populates the data and the ROWS currently in the table to see if it is necessary to update. If not, it doesn't do anything.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文