RATreeView icon indicating copy to clipboard operation
RATreeView copied to clipboard

Inserting Object at root of treeview

Open A1exandre opened this issue 8 years ago • 4 comments

Hi,

I took the swift example project and I'm trying to add an object at the root of the tree. I read on another post (issue #117 ) that I should first modify the data model, then call insertItemsAtIndexes.

I created this function:

private func addItem(newItem:DataObject) { data.append(newItem) myTree.insertItemsAtIndexes(NSIndexSet.init(index: 0), inParent: nil, withAnimation: RATreeViewRowAnimationNone)

}

It works well at first sight but I have 2 issues:

  • A new item is added at root, but it is a copy of the item below it, not the one I added.
  • When I try to add an item at the second level by clicking on the "+" button that is already implemented in the demo, I get

'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (6) must be equal to the number of rows contained in that section before the update (3), plus or minus the number of rows inserted or deleted from that section (1 inserted, 0 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).'

What am I doing wrong? Isn't there an easier way to add an item at the root? I must be missing something.

Thanks!

A1exandre avatar Mar 23 '16 17:03 A1exandre

I find it simpler to just update the data model and then call refresh.

joshjack avatar Mar 23 '16 17:03 joshjack

Indeed, it works quite well but then you can't animate the new row like when you add one with insertItemsAtIndexes

A1exandre avatar Mar 23 '16 17:03 A1exandre

I have same question. Do you have any solution yet? @A1exandre

zzyspace avatar Apr 28 '18 01:04 zzyspace

#117

zzyspace avatar Apr 28 '18 01:04 zzyspace