Author Topic: Dynamically adding items to scrollview via code. How to update scrollview.  (Read 2216 times)

wallabie

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 200
    • View Profile
Hi,

I'm trying to add items to a scrollview that has a Grid.  The new items are being added by instantiating a prefab and then parenting to the Grid.  The problem is that the scrollList does not update to show the new added item.  I have a feeling that this is not the correct way to add items dynamically to the scrollview.  What is the recommended way to do this. 

This is another use case of trying to make an NGUI component data aware to dynamically changing data.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
UIGrid.Reposition() must be called after adding any new children to the grid.

UIWidget.MarkParentAsChanged() must be called if you moved the widget from A to B.

wallabie

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 200
    • View Profile
"UIWidget.MarkParentAsChanged() must be called if you moved the widget from A to B."

You mean when one of the items of ScrollList A is moved to ScrollList B?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
That's one example, yup. If you change a transform.parent, you must notify that transform that its parent has changed -- you can use the NGUITools.MarkParentAsChanged helper function and it will do the recursive updates for you.