gpt4 book ai didi

ios - 尝试更新 TableView 中的行数时出错

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:06:32 26 4
gpt4 key购买 nike

我对如何向表格 View 添加行有点困惑。

我有一个数组,它定期向其中添加值。每次使用以下代码行将新值添加到数组时,我都会尝试更新行数:

// listOfMembers if a 
[[self tableView] beginUpdates]; [tableView numberOfRowsInSection:[listOfMembers count]];
[[self tableView] endUpdates];

[[self tableView] beginUpdates];
[tableView reloadRowsAtIndexPaths:[tableView indexPathsForVisibleRows] withRowAnimation:UITableViewRowAnimationNone];
[[self tableView] endUpdates];

但是这对更改行数不起作用.. 可能我误解了表格的更新方式。我收到此错误:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0.  The number of rows contained in an existing section after the update (5) must be equal to the number of rows contained in that section before the update (4), plus or minus the number of rows inserted or deleted from that section (0 inserted, 0 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).'

崩溃在线:

[tableView reloadRowsAtIndexPaths:[tableView indexPathsForVisibleRows] withRowAnimation:UITableViewRowAnimationNone];

我应该如何清楚地更新我的表格 View 我这样做是错误的。

最佳答案

好的,所以这个问题的答案就是简单地调用函数 reloadData。例如:

[tableViewOutlet reloadData];

关于ios - 尝试更新 TableView 中的行数时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12409616/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com