Author Topic: Proper way to reposition UITable (dynamically generated)  (Read 1190 times)

Ernest

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 40
    • View Profile
Proper way to reposition UITable (dynamically generated)
« on: January 28, 2014, 05:32:50 AM »
Hey,
I know this is a current topic, coming back regularly on this forum, but i did not find a satisfying answer!
What is the best way to re-populate a table? (a friends list for example)
I mean, should i:
- Clear the table (delete the children), add the new ones, reposition the table
- Desactivate the children, add the new ones, reposition the table, delete the desactivated ones
- Add the new ones desactivated, switch the state of the old and new ones, reposition the table
- Move the table in a hidden layer, and do as in the first dash
And should i call reposition after each element added or after all of them have been added to the table?
I have plenty of tricks, but none of them works as expected... Most of the time, the children are not displayed correctly (space before/between children due to an old children location (Hide Inactive is on); children centered on top of each other due to the table state (false, if in a disabled tab for example)).
In brief, i would like to know the correct workflow to handle the common cases of table repopulation.
Thanks :)

PS: i don't want the user to see the repopulation process (at most a little blink). But i can add a spinner.
« Last Edit: January 28, 2014, 05:45:03 AM by Ernest »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
Re: Proper way to reposition UITable (dynamically generated)
« Reply #1 on: January 28, 2014, 11:22:53 AM »
NGUITools.Destroy the table's children, add new ones, reposition the table.

Ernest

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 40
    • View Profile
Re: Proper way to reposition UITable (dynamically generated)
« Reply #2 on: January 29, 2014, 05:16:04 AM »
Okay. I think this is very important to specify somewhere that NGUITools.Destroy() should be used instead of Destroy(), and repositionNow = true instead of Reposition() (and even NGUITools.AddChild() instead of Instantiate()).
It could save a lot of time to many people, trying to display the table's elements correctly.
« Last Edit: January 29, 2014, 10:32:31 AM by Ernest »

maaya

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 22
    • View Profile
Re: Proper way to reposition UITable (dynamically generated)
« Reply #3 on: May 01, 2014, 08:53:54 PM »
This was a life saver! Thank you. I once struggled with scales of the objects created from prefabs and learnt about NGUITools. And now NGUITools.Destroy for UITable elements to position correctly!
I now have a post-it to use NGUITools.Add/Destroy :)