0

Code here:

[self.textView addObserver:self forKeyPath:@"contentSize" options:NSKeyValueObservingOptionNew context:nil];

observing method

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
    NSLog(@"change %@", change);
}

Every time I typed in words in the textView, the method just get called even there is no change in contentSize. And there is no problem in iOS7.

What might cause this problem? It is a bug in UIKit?

shanabus
  • 12,989
  • 6
  • 52
  • 78
Gary Lyn
  • 1,088
  • 9
  • 11

1 Answers1

0

Try this,

[self.textView addObserver:self forKeyPath:@"contentSize" options:(NSKeyValueObservingOptionOld|NSKeyValueObservingOptionNew) context:@"mycontext"];  

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
    NSString *oldValue = [change objectForKey:NSKeyValueChangeOldKey];
    NSString *newValue = [change objectForKey:NSKeyValueChangeNewKey];

    NSLog(@"OldValue %@",oldValue);
    NSLog(@"NewValue %@",newValue);
}
karthika
  • 4,085
  • 3
  • 21
  • 23
  • I just print the change, its like this{ kind = 1; new = "NSSize: {223, 36}"; old = "NSSize: {223, 36}"; } – Gary Lyn Oct 21 '13 at 12:43
  • you want to change of "text" in textview or contentsize? did you type the long text and short text simultaneously and check? – karthika Oct 21 '13 at 12:46
  • I want to change the textview's superview's frame to fit the content, like the system message input view. – Gary Lyn Oct 21 '13 at 12:49
  • see this link, http://vectorvector.tumblr.com/post/1077884802/how-to-vertically-center-a-uitextview – karthika Oct 21 '13 at 12:58