Author Topic: UITable.Reposition() gives different results in code than from Inspector  (Read 3683 times)

Shifty Geezer

  • Full Member
  • ***
  • Thank You
  • -Given: 7
  • -Receive: 9
  • Posts: 226
    • View Profile
I add children prefabs to my UITable. I call UITable.Reposition. It spaces them evenly across the table without a limit on row height, so with two items, one is at the top and the other at the bottom, or with three, they are spread across the height of the table. But if I execute the script in the Inspector, it arranges them correctly butted up against each other.

eg.
  1.                         go_temp = NGUITools.AddChild (go_param_table, prefab_param_slider);
  2.                         go_temp.name = "Param 00";
  3.                         go_temp.SendMessage("Init");
  4.                         go_temp.SendMessage("setParam", PARAMS.CONFUSION);
  5.  
  6.                         go_temp = NGUITools.AddChild (go_param_table, prefab_param_slider);
  7.                         go_temp.name = "Param 01";
  8.                         go_temp.SendMessage("Init");
  9.                         go_temp.SendMessage("setParam", PARAMS.DISCOURSE);
  10.                        
  11.                         go_temp = NGUITools.AddChild (go_param_table, prefab_param_slider);
  12.                         go_temp.name = "Param 02";
  13.                         go_temp.SendMessage("Init");
  14.                         go_temp.SendMessage("setParam", PARAMS.SENTIMENT);
  15.  
  16.                         table_params.Reposition();
  17.  
Three prefabs added to the table of heights 180 pixels in a 1080 base height UI. Executing this code, the items in the table are at vertical positions -90, -270 and -510 respectively. If I then execute the script from the Inspector, they rearrange to the correct -100, -290 and -450.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UITable.Reposition() gives different results in code than from Inspector
« Reply #1 on: February 16, 2014, 02:26:54 AM »
Why are you sending the Init function? Some NGUI classes have it (such as grid, table, input, button etc), so you may not be calling what you think. If you are trying to call your own function, do a GetComponent<YourComponent> and modify its values directly. Don't use SendMessage.

Shifty Geezer

  • Full Member
  • ***
  • Thank You
  • -Given: 7
  • -Receive: 9
  • Posts: 226
    • View Profile
Re: UITable.Reposition() gives different results in code than from Inspector
« Reply #2 on: February 16, 2014, 05:28:08 AM »
That's my own Init function. I've tried renaming it to InitSetup() and then tried calling that with GetComponent instead of SendMessage, but the results are still the same.

I notice that if I select the page of controls twice, I get a different layout the second time (still not properly aligned), but subsequent repopulatings of the table don't change it. If I run Repopulate() twice in code, it makes no difference.

Edit: Okay, that pointed to the problem. I am removing the contents deleting the children with Unity's Destroy. Using NGUITools.Destroy(), problem's solved.
« Last Edit: February 16, 2014, 05:33:36 AM by Shifty Geezer »