• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Loop between observers with KVO from UIScrollView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Loop between observers with KVO from UIScrollView


  • Subject: Re: Loop between observers with KVO from UIScrollView
  • From: talesp <email@hidden>
  • Date: Tue, 21 Jun 2011 14:16:38 +0000 (GMT)

Thank you for the answer. It just worked!

About the notes:

1.: should I just check if the object is different from self? Or some more "complicated"? And what should I check as keyPath?

2.: if I send a context parameter from observer (the context can be a NSString for example, right?), should I chech if the string is expected? And I only should call super if the context is invalid? Reading Apple documentation I saw that I should ever call super, but when I did it, the app crashed (I did not went look what was wrong. Should I or it's not really necessary?)

Sorry, but I'm pretty new with KVO. I'm just read the KVO quick star guide and KVO programming guide.

Em 20/06/2011, às 02:58, Quincey Morris escreveu:

On Jun 19, 2011, at 11:59, Tales Pinheiro de Andrade wrote:

  if ([keyPath isEqualToString:@"contentOffset"]) {
      CGPoint newContentOffset = [(UIScrollView *)object contentOffset];
      newContentOffset.y = self.contentOffset.y;
      self.contentOffset = newContentOffset;
  }

It may be as simple as changing the above pattern to this pattern:

  if ([keyPath isEqualToString:@"contentOffset"]) {
      CGPoint newContentOffset = [(UIScrollView *)object contentOffset];
      newContentOffset.y = self.contentOffset.y;
      if (!CGPointEqualToPoint (self.contentOffset, newContentOffset))
          self.contentOffset = newContentOffset;
  }


But note:

1. You should really check the object (at least its class) as well as the keyPath.

2. You should really use a context parameter that's unique for your observations, and call super if the context isn't what you expect.



_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Loop between observers with KVO from UIScrollView
      • From: Quincey Morris <email@hidden>
  • Prev by Date: Re: attribute is an array?
  • Next by Date: Re: So... we can't use UIWebView (with a delegate) on a page that's pushed onto a UINavigationController stack?
  • Previous by thread: Re: Loop between observers with KVO from UIScrollView
  • Next by thread: Re: Loop between observers with KVO from UIScrollView
  • Index(es):
    • Date
    • Thread