Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: wallabie on March 30, 2014, 02:39:35 AM

Title: Dynamically adding items to scrollview via code. How to update scrollview.
Post by: wallabie on March 30, 2014, 02:39:35 AM
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.
Title: Re: Dynamically adding items to scrollview via code. How to update scrollview.
Post by: ArenMook on March 30, 2014, 07:35:36 AM
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.
Title: Re: Dynamically adding items to scrollview via code. How to update scrollview.
Post by: wallabie on March 30, 2014, 02:30:49 PM
"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?
Title: Re: Dynamically adding items to scrollview via code. How to update scrollview.
Post by: ArenMook on March 30, 2014, 02:45:55 PM
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.