Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: JRufer on September 27, 2013, 01:54:40 PM

Title: UIGrid sorting in editor but not on iOS...
Post by: JRufer on September 27, 2013, 01:54:40 PM
I have a UIGrid to display an ordered list of items. When I view it in the editor, they are sorted correctrly but when I run the compiled app on my iPad, the items are out of order. My code for loading the grid is below. Any help would be appreciated.

  1.  
  2. for(int i=0; i<items.Length; i++){
  3.                         string itemKey = items[i];
  4.                         string gameObjectName = itemKey.Substring(sessionID.Length);
  5.                         Debug.LogError("real key = "+ gameObjectName);
  6.                         ItemState state = GameObject.Find(gameObjectName).GetComponent<ItemState>();
  7.                         state.LogValues();
  8.                        
  9.                         if(showUnaltered == true || altered == true){
  10.                                 GameObject row = NGUITools.AddChild(ListParent, ListItemPrefab);
  11.                                 row.name = i.ToString().PadLeft(8,'0');;
  12.                                 populateRow(state, row, forReview, i);
  13.                         }
  14.                 }
  15.                 UIGrid grid = ListParent.GetComponent<UIGrid>();
  16.                 grid.cellHeight = 175; 
  17.                 grid.repositionNow = true;
  18.  
Title: Re: UIGrid sorting in editor but not on iOS...
Post by: Nicki on September 27, 2013, 02:10:42 PM
If the grid isnot set to sorted, it should position the children after when they were added.

If you put it to sorted, it's by game object name. I recommend you name your gameobjects and set it to sorted so you get control.
Title: Re: UIGrid sorting in editor but not on iOS...
Post by: JRufer on September 27, 2013, 02:37:09 PM
Thanks for the quick reply. The UIGrid is set to sorted and in the loop I am renaming the rows with 0 padded numbers. This is what made it work in the editor. What I don't know is why they are not sorted on the target device.
Title: Re: UIGrid sorting in editor but not on iOS...
Post by: ArenMook on September 27, 2013, 06:24:02 PM
My guess is your renaming happens after the UIGrid sorts everything. You might want to tell it to re-sort everything after you're done renaming stuff.
Title: Re: UIGrid sorting in editor but not on iOS...
Post by: JRufer on September 27, 2013, 06:49:27 PM
I could programmatically call sort after all the children are added but the public sort property seems to take care of that, even for dynamically added children. The grid is always sorted in the editor. I can't figure out what is going wrong in the deliverable.
Title: Re: UIGrid sorting in editor but not on iOS...
Post by: ArenMook on September 27, 2013, 07:08:55 PM
As I said, double-check the order in which things get called. It may not be the same order as in the editor. To be safe, always sort after renaming things.