I just want to know how can I fire some function when button title change ? i tried to use this command but nothing work :
[button addTarget:self
action:@selector(function:)
forControl:UIControlEventValueChange];
You can use an observer in your viewcontroller that has an outlet to the button:
First add the observer (in viewDidLoad for example)
[self.button addObserver:self
forKeyPath:@"titleLabel.text"
options:NSKeyValueObservingOptionNew
context:NULL];
Override default observer method on your 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 yourself as observer in the dealloc function
[self.button removeObserver:self forKeyPath:@"titleLabel.text"];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With