Author Topic: UITable Insert  (Read 1411 times)

Yukichu

  • Full Member
  • ***
  • Thank You
  • -Given: 3
  • -Receive: 8
  • Posts: 101
    • View Profile
UITable Insert
« on: June 17, 2014, 08:20:58 PM »
I've tried and tried to do this on my own, but I've failed miserably, so I'm back to the forums feeling like things either don't work right in my brain, or in NGUI. 

I have a UITable.  It gets filled with stuff.  I want to insert a new object into the next-to-last position.  When I do this, the object always shows up in the last position, unless I leave/return to the table which involves disabling/enabling the gameobjects.

  1.         int index = m_tblCharSelectTable.children.Count - 1;
  2.  
  3.         GameObject child = NGUITools.AddChild(m_tblCharSelectTable.gameObject, m_btnCharSelectNew.gameObject);
  4.  
  5.         mTable.children.Insert(index, child.transform);
  6.         mTable.repositionNow = true;
  7.         //NGUITools.MarkParentAsChanged(mTable.gameObject);
  8.  

It doesn't really matter where I try to put the index if I recall, it always adds it at the last object until I disable/enable the panel.  I'll have to investigate that more, but it doesn't matter if I mark parent as changed, repositionNow, reposition(), whatever...    it's always adding it to the last index.

So I must be doing this wrong.  Advice on how to do this correctly please?

Yukichu

  • Full Member
  • ***
  • Thank You
  • -Given: 3
  • -Receive: 8
  • Posts: 101
    • View Profile
Re: UITable Insert
« Reply #1 on: June 18, 2014, 11:50:49 AM »
I guess nevermind.

The way I was 'correcting' this was by removing all the children and recreating it each time when you left this menu and then came back later.

So, to do this while still viewing the menu... I'm just doing the same thing now.  I destroy all the children in the grid and recreate it all on the fly in the correct order.

Works for now, but if there is a better way to do this... I've love to know.  I presume it works from some examples I think I remember.  Maybe I ought to go looks at some when I'm bored.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UITable Insert
« Reply #2 on: June 18, 2014, 04:41:35 PM »
Unfortunately the only way to insert a child into a specific location would be to have the table sort its children based on some criteria, such as alphabetic names.