UITableView 中的部分遇到问题

发布于 2025-01-01 12:41:12 字数 613 浏览 2 评论 0原文

我的搜索方法中有以下代码可以更新表格视图。

for (int x = 0; x < [array count]; x++) {
//network stuff here
self.searchedReservations = [aSearchObjectType objectsFromServerDictionaries:aResultsArray];
[self.aTableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationFade];
}

数组中的每个对象代表表中的一个部分,大多数情况下计数为 4,即 4 个部分。

现在,代码正在为表单元格中的所有部分加载相同的数据。而不是表的每个部分的唯一数据。

这是加载单元格的代码。我缺少一些将数据映射到表右侧部分的逻辑。

MyClass *object = [self.searchedReservations objectAtIndex:iIndexPath.row];
cell.textLabel.text = object.customerFullName;

I have the following code in my search method that updates the tableview.

for (int x = 0; x < [array count]; x++) {
//network stuff here
self.searchedReservations = [aSearchObjectType objectsFromServerDictionaries:aResultsArray];
[self.aTableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationFade];
}

Each object in the array represent a section in my table, for most cases the count will be 4, so 4 sections.

Right now, the code is loading the same data for all sections in the table's cells. Instead of the unique data for each section of the table.

Here is the code that loads the cells. I'm missing some logic that maps the data to the right section of the table.

MyClass *object = [self.searchedReservations objectAtIndex:iIndexPath.row];
cell.textLabel.text = object.customerFullName;

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

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

发布评论

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

评论(1

终难愈 2025-01-08 12:41:12

我假设您的“cellForRowAtIndexPath”方法中有以下代码:

MyClass *object = [self.searchedReservations objectAtIndex:iIndexPath.row];
cell.textLabel.text = object.customerFullName;

表被组织成多个部分,然后每个部分中都有行。每个部分的行再次从零开始。

如果您位于第 0 节,则加载单元格 0 ,上面的代码不会考虑节号,只考虑行号 - 因此它正在加载:

[self.searchedReservations objectAtIndex:0] 

以填充单元格。

当您在第 1 部分中加载第 1 部分中的单元格 0 时,您将检索到完全相同的值,因为您只是使用行号。 IE。您仍在加载

[self.searchedReservations objectAtIndex:0]

您可能认为您正在加载每个部分之间更改“searchedReservations”对象的值(这就是您在上面的循环中尝试执行的操作),但我不确定这是有效的(因为填充 searchedReservation 的代码似乎在每个循环计数器中没有做任何不同的事情)。此外,第一次加载表时,它将遍历所有部分中的所有行。

我认为您需要在填充单元格时使用 indexPath.section 字段以及 indexPath.row 字段,以确保您在适当的部分中设置适当的行。

还可以使用调试器查看 cellForRowAtIndexPath 方法和循环中发生的情况,并确保您为循环的每次增量获取/使用不同的“searchedReservations”对象,并且该对象与 cellForRowAtIndexPath 中的“searchedReservations”对象匹配方法。

I assume you have the code below in your 'cellForRowAtIndexPath' method:

MyClass *object = [self.searchedReservations objectAtIndex:iIndexPath.row];
cell.textLabel.text = object.customerFullName;

Tables are organised into sections, then within each section there are rows. The rows start at zero again for each section.

If you are on section 0, loading cell 0 this code above is not taking the section number into account, only the row number - so it is loading:

[self.searchedReservations objectAtIndex:0] 

to populate the cell.

When you are on section 1, loading cell 0 in section one, you are retrieving exactly the same value because you are just using the row number. ie. you're still loading

[self.searchedReservations objectAtIndex:0]

You may think that you are changing the value of the 'searchedReservations' object between the loading of each section (this is what it looks like you're trying to do in the loop above) but I'm not sure that this is working (as the code the populate searchedReservation doesn't seem to do anything different in each loop counter). Also the first time the table loads it will run through all of the rows in all of the sections anyway.

I think you need to either use the indexPath.section field as well as the indexPath.row field at the time you are populating the cell to ensure you are setting the appropriate row in the appropriate section.

Also use the debugger to see whats going on in your cellForRowAtIndexPath method and in your loop and make sure that you are getting/using a different 'searchedReservations' object for each incrementation of the loop and that this matches the 'searchedReservations' object in the cellForRowAtIndexPath method.

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