Author Topic: Hashtable param for UIButton.onClick event  (Read 3468 times)

yutof

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Hashtable param for UIButton.onClick event
« on: April 10, 2014, 10:45:46 PM »
Hi there,

I have a generic function that I want to hook to multiple UIButtons. But I can't do so using following API call due to the fact I don't know to tell which button called the method.

EventDelegate.Add(btn.onClick, onClickBtn)

I've looked into UIButton class and found out that adding a generic parameter(like a Hashtable) to onClick event is not that hard. (Modifying onClick it self takes quite a bit of effort, but creating new delegate, or a list of delegates like following is not that difficult)

  public delegate void CallbackWithParam(Hashtable hash);
  public CallbackWithParam onClickWithParam;
  public Hashtable onClickParam;

and then call onClickWithParam at the place where onClick is executed.

Would you, NGUI developers, consider updating UIButton so that we can add a generic parameter to the onClick event? Or is there another way to do so other than modifying UIButton class?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Hashtable param for UIButton.onClick event
« Reply #1 on: April 11, 2014, 05:30:17 AM »
You can set parameters with delegates. With the On Click notification it's far easier to do it in the Inspector when selecting the button, but code is also possible.

Even without doing anything you can always determine which button called the delegate by checking UIButton.current.