ios - how to know if UIButton titlelable.text changed -


i want know how can fire function when button title change ? tried use command nothing work :

[button addtarget:self             action:@selector(function:)         forcontrol:uicontroleventvaluechange]; 

you can use observer in viewcontroller has outlet button:

  1. first add observer (in viewdidload example)

    [self.button addobserver:self                forkeypath:@"titlelabel.text"                   options:nskeyvalueobservingoptionnew                   context:null]; 
  2. override default observer method on viewcontroller

    - (void)observevalueforkeypath:(nsstring *)keypath                        ofobject:(id)object                          change:(nsdictionary *)change                         context:(void *)context {      if ([keypath isequaltostring:@"titlelabel.text"]) {         // value changed         uibutton *button = object;         nsstring *title = button.titlelabel.text;     } } 
  3. remove observer in dealloc function

    [self.button removeobserver:self forkeypath:@"titlelabel.text"]; 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -