Reputation: 3564
Just had a question regarding the UILabel class. I know that the UITextField control has a delegate for when the editing has changed, but I was wondering if the UILabel has a similar field. The reason I ask is that my application queries the network for when certain pieces of information change and updates them accordingly and I don't want to hard code in my update the name of the label I want to watch for just to do a small task regarding it. If it has a delegate or something equivalent to it so that my class can monitor for this information that would be great.
If not then any advice would be greatly appreciated.
Upvotes: 2
Views: 5491
Reputation: 5210
You can use KVO to find out or perform some code when the text changes like this :
[somelabel addObserver:self forKeyPath:@"text" options:NSKeyValueObservingOptionNew context:NULL];
and then listen for the changes like this
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
NSLog(@"the text changed");
}
Upvotes: 19
Reputation: 34912
A UILabel
cannot change its text without your code doing it, so why would there ever be a delegate that told you when it's changed? You already know... UITextField
has one because the user can edit the text so you're told when it's changed.
So basically, no, there is no delegate method and you shouldn't even need one.
Upvotes: 1