This is my code where I add the children but every time I try to call grid.GetComponent<UIGrid>.Reposition(); Unity crashes. I also have tried just calling grid.GetComponent<UIGrid>().Reposition(); after adding all the children but that still doesn't work. I also tried this on another computer just to make sure it wasn't my computer. I am basically trying to create a leaderboard and maybe I am approaching this the wrong way and when you call reposition does it also sort the children?
foreach(int k in totals.Keys)
{
leaderboardsprite.name = totals[k];
//leaderboardsprite.transform.FindChild("Label").GetComponent<UILabel>().SetDimensions(200,25);
leaderboardsprite.transform.FindChild("Label").GetComponent<UILabel>().text = totals[k]+" "+k.ToString();
NGUITools.AddChild(this.gameObject,leaderboardsprite);
Debug.Log("initialize");
grid.GetComponent<UIGrid>().Reposition();
}