Author Topic: UIGrid sorting in editor but not on iOS...  (Read 3437 times)

JRufer

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
UIGrid sorting in editor but not on iOS...
« 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.  

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: UIGrid sorting in editor but not on iOS...
« Reply #1 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.

JRufer

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: UIGrid sorting in editor but not on iOS...
« Reply #2 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.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIGrid sorting in editor but not on iOS...
« Reply #3 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.

JRufer

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: UIGrid sorting in editor but not on iOS...
« Reply #4 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.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIGrid sorting in editor but not on iOS...
« Reply #5 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.