Tasharen Entertainment Forum
Support => NGUI 3 Support => Topic started by: xiangting on April 20, 2015, 09:45:23 AM
-
My grid is in the scroll view. My action is to delete some labels in grid and regenerate some to it. Sometimes it appears in wrong position, and sometime it doesn't show up until I click on it. I've tried the UIWidget.MarkAsChanged(). But it does not work.
-
Post some code. How do you add / remove entries?
-
I first delete all the children:
public void DeleteAllStory()
{
int count = grid.transform.childCount;
for(int i = 0; i < count; i++ )
{
Destroy(grid.transform.GetChild(i).gameObject);
}
}
then generate new ones:
public void GetAllTheStory()
{
foreach(Story s in bsl.Stories)
{
GameObject newButton = (GameObject)Instantiate(myStoryButton);
newButton.name = s.StoryName;
newButton.transform.parent = this.transform;
newButton.transform.localScale = Vector3.one;
newButton.GetComponent<UILabel>().text = s.StoryName;
}
GetComponent<UIWidget>().MarkAsChanged();
}
-
You need to use NGUITools.Destroy instead of just Destroy.
Unity's Destroy() call is delayed. It's not immediate. If you iterate through the list after destroying the children, you will see all of them still there.
Likewise, don't use Instantiate. Use NGUITools.AddChild. Read the sticky post at the top of this forum.
http://www.tasharen.com/forum/index.php?topic=11208.0