Author Topic: UIPopupList Set-method  (Read 7436 times)

DJVDJV

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 30
    • View Profile
UIPopupList Set-method
« on: November 29, 2016, 04:46:10 PM »
Hellos,

I try set UIPopupList selected item with method:
public void Set (string value, bool notify = true)
(in UIPopupList)

But there seems be row 321:
mSelectedItem = null;

That resets value.. if I comment this row away all works great.
How I should set current value right way (and without changing NGUI code)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIPopupList Set-method
« Reply #1 on: November 30, 2016, 03:26:18 PM »
I've answered this question a couple of times now. The popup list's selection is only known while the popup is open. If you want to cache it, then do just that.
  1. using UnityEngine;
  2.  
  3. [RequireComponent(typeof(UIPopupList))]
  4. public class SavedSelection : MonoBehaviour
  5. {
  6.     public string selection;
  7.  
  8.     UIPopupList mList;
  9.  
  10.     void Start ()
  11.     {
  12.         mList = GetComponent<UIPopupList>();
  13.         EventDelegate.Add(mList.onChange, delegate () { selection = mList.value; });
  14.     }
  15. }