使用 RATreeView 的 tableView endUpdates 崩溃
Crash with tableView endUpdates using RATreeView
我在 https://github.com/Augustyniak/RATreeView 上使用 Rafał Augustyniak 的 RATreeView 组件。
使用 github 上发布的 /Demo 代码:
添加:
RADataObject *rdo = [self.data objectAtIndex:0];
[self.treeView expandRowForItem:[rdo.children objectAtIndex:0]];
在 viewWillAppear 的底部。
将 phone 个对象的行更改为:
(void)loadData
{
RADataObject *phone2 = [RADataObject dataObjectWithName:@"Phone 2" children:nil];
RADataObject *phone3 = [RADataObject dataObjectWithName:@"Phone 3" children:nil];
RADataObject *phone4 = [RADataObject dataObjectWithName:@"Phone 4" children:nil];
RADataObject *phone1 = [RADataObject dataObjectWithName:@"Phone 1" children:[NSArray arrayWithObjects:phone2, phone3, phone4, nil]];
RADataObject *phone = [RADataObject dataObjectWithName:@"Phones"
children:[NSArray arrayWithObjects:phone1, nil]];
(这给出了一个嵌套列表,其中 phone -> phone 1 -> phone2,phone3,phone4)
这重现了我在我的应用程序中遇到的崩溃。
它崩溃于:
(void)expandCellForTreeNode:(RATreeNode *)treeNode withRowAnimation:(RATreeViewRowAnimation)rowAnimation
EXC_BAD_ACCESS 用于:
[self.tableView endUpdates];
我已经跟踪了几天,但不确定如何解决此崩溃(甚至不知道为什么会发生)。
我使用你的代码得到的错误消息如下。要重现此错误,请移动
[self.treeView expandRowForItem:[rdo.children objectAtIndex:0]];
到 viewDidAppear
.
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 (24) must be equal to the number of
rows contained in that section before the update (12), plus or minus
the number of rows inserted or deleted from that section (24 inserted,
0 deleted) and plus or minus the number of rows moved into or out of
that section (0 moved in, 0 moved out).'
行数改为24,复制现有行插入到table,但插入不成功
看来你要做的是展开一个子节点,你可以通过查看didSelectRowAtIndexPath
委托方法的实现来实现,因为展开一行就像点击一行一样。要手动添加以下代码。
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
RATreeNode *treeNode = [self.treeView treeNodeForIndexPath:indexPath];
[self.treeView expandCellForTreeNode:treeNode];
NSIndexPath *indexPath1 = [NSIndexPath indexPathForRow:1 inSection:0];
RATreeNode *treeNode1 = [self.treeView treeNodeForIndexPath:indexPath1];
[self.treeView expandCellForTreeNode:treeNode1];
就像依次点击第 0 行和第 1 行一样。您还需要导入此头文件。
#import "RATreeView+Private.h"
我在 https://github.com/Augustyniak/RATreeView 上使用 Rafał Augustyniak 的 RATreeView 组件。
使用 github 上发布的 /Demo 代码:
添加:
RADataObject *rdo = [self.data objectAtIndex:0];
[self.treeView expandRowForItem:[rdo.children objectAtIndex:0]];
在 viewWillAppear 的底部。
将 phone 个对象的行更改为:
(void)loadData
{
RADataObject *phone2 = [RADataObject dataObjectWithName:@"Phone 2" children:nil];
RADataObject *phone3 = [RADataObject dataObjectWithName:@"Phone 3" children:nil];
RADataObject *phone4 = [RADataObject dataObjectWithName:@"Phone 4" children:nil];
RADataObject *phone1 = [RADataObject dataObjectWithName:@"Phone 1" children:[NSArray arrayWithObjects:phone2, phone3, phone4, nil]];
RADataObject *phone = [RADataObject dataObjectWithName:@"Phones"
children:[NSArray arrayWithObjects:phone1, nil]];
(这给出了一个嵌套列表,其中 phone -> phone 1 -> phone2,phone3,phone4)
这重现了我在我的应用程序中遇到的崩溃。
它崩溃于:
(void)expandCellForTreeNode:(RATreeNode *)treeNode withRowAnimation:(RATreeViewRowAnimation)rowAnimation
EXC_BAD_ACCESS 用于:
[self.tableView endUpdates];
我已经跟踪了几天,但不确定如何解决此崩溃(甚至不知道为什么会发生)。
我使用你的代码得到的错误消息如下。要重现此错误,请移动
[self.treeView expandRowForItem:[rdo.children objectAtIndex:0]];
到 viewDidAppear
.
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 (24) must be equal to the number of rows contained in that section before the update (12), plus or minus the number of rows inserted or deleted from that section (24 inserted, 0 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).'
行数改为24,复制现有行插入到table,但插入不成功
看来你要做的是展开一个子节点,你可以通过查看didSelectRowAtIndexPath
委托方法的实现来实现,因为展开一行就像点击一行一样。要手动添加以下代码。
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
RATreeNode *treeNode = [self.treeView treeNodeForIndexPath:indexPath];
[self.treeView expandCellForTreeNode:treeNode];
NSIndexPath *indexPath1 = [NSIndexPath indexPathForRow:1 inSection:0];
RATreeNode *treeNode1 = [self.treeView treeNodeForIndexPath:indexPath1];
[self.treeView expandCellForTreeNode:treeNode1];
就像依次点击第 0 行和第 1 行一样。您还需要导入此头文件。
#import "RATreeView+Private.h"