以前的 UITableView 中的项目出现在新的 UITableView 中
我的表格视图出现问题,因为我从导航控制器中弹出一个表格视图,然后推送一个具有类似源数据的新表格视图。不知何故,我看到了旧表格视图中的单元格。有什么想法吗?
I am having an issue with my tableviews as I pop one tableview off my navigation controller and then pushing a new one on with similar data for the source. Somehow I am seeing cells from the old tableview. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果这是两个不同的表视图,您可能希望为它们提供不同的重用标识符,例如
对于 FirstTable:
UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"FirstTableViewCell"];
对于第二个表:
UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"SecondTableViewCell"];
if these are two different table views you probably want to give them different reuse identifiers, e.g.
for the FirstTable:
UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"FirstTableViewCell"];
for the SecondTable:
UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"SecondTableViewCell"];
哇,刚刚弄清楚,我正在对单元格进行出队(并使用自定义单元格)以提高响应能力并将引用存储在内存中,当我弹出旧的表格视图时,我将其设置为弹出动画。这以某种方式将单元格保留在内存中足够长的时间,以便当我将新的 UITableView 推入堆栈时,它正在访问取消排队的单元格并呈现它们而不是新数据。因此,如果您打算呈现类似的数据并弹出 UITableView 以将其替换为新数据,请在没有动画的情况下弹出它...
或者如上所述为它们提供一个特定的唯一标识符。 (但我的解决方案只是避免使用动画。
Wow, just figured it out, I was dequeing cells (And using Custom Cells) to increase responsiveness and storing the references in memory, and when I popped the old tableview off I was setting it to animate the pop. This somehow held the cells in memory just long enough so that when I pushed the new UITableView on the stack, it was accessing the de-qued cells and presenting them instead of the new data. So if you plan on presenting similar data and are popping off a UITableView to replace it with the new data, pop it without animation...
Or give them a specifically unique identifier as mentioned above. (But my solution was just to avoid using animation.