0

Hi I am developing IOS application in which I am using add observer with key value pair. But it's not working. I did following things:

[self.scrollView addObserver:self
                  forKeyPath:@"new"
                     options:(NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld)
                     context:nil];

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {

    // inside here ... 
}

But its not calling the above method. If I change forKeyPath to contentOffset then its working fine. But I want to change that value. Am I doing something wrong? Need Help. Thank you.

rdurand
  • 7,342
  • 3
  • 39
  • 72
nilkash
  • 7,408
  • 32
  • 99
  • 176
  • 2
    what is "new"? I don't think it's a property of UIScrollView – Stavash Jun 10 '14 at 10:02
  • Can you please share a little more info on what are you trying to observe? Because `new` isn't a property of `UIScrollView` (and that's why the method isn't called)... – Alladinian Jun 10 '14 at 10:02
  • I want to apply different property for my scrollview rather than content offset but it is not working. – nilkash Jun 10 '14 at 10:04
  • Like Stavash mentioned you can not observer a value that is not part of the key for ScrollView. This might help: http://stackoverflow.com/questions/8729134/how-do-i-properly-observe-the-contentoffset-property-of-my-scrollview-subclass – Ricky Jun 10 '14 at 10:17

1 Answers1

1

[webView.scrollView addObserver:self forKeyPath:@"contentOffset" options:NSKeyValueObservingOptionNew context:nil];

You need to give the property of the scrollview here.

bvsss
  • 72
  • 6