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:
first add observer (in viewdidload example)
[self.button addobserver:self forkeypath:@"titlelabel.text" options:nskeyvalueobservingoptionnew context:null];
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; } }
remove observer in dealloc function
[self.button removeobserver:self forkeypath:@"titlelabel.text"];
Comments
Post a Comment