• 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: IKImageView selection issue
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: IKImageView selection issue


  • Subject: Re: IKImageView selection issue
  • From: Graham Cox <email@hidden>
  • Date: Fri, 6 Feb 2009 14:12:44 +1100


On 6 Feb 2009, at 11:50 am, Christian Graus wrote:

I have a class derived from IKImageView, and in my initWithFrame ( which is
the only init I call ), I set [self setDelegate:self];
Once I do this, I have this code:


- (void) selectionRectAdded: (IKImageView *) imageView

{

NSLog(@"Created sel rect");

}

I run the app and make a selection. This log message is displayed twice (
sadly, both times before the selection ends, which is a PITA ). Now, here's
where it gets interesting. My app crashes with a bad access, and then XCode
reports that it's loading 400000 stack frames or something. Which makes me
think I've created infinite recursion, but I don't see how. I only set the
delegate in initWithFrame, so I don't see how I could have set the delegate
over and over ( does it even work that way ? ). Does anyone have any
suggestion what I may be doing wrong, please?



Setting an object's delegate to itself is never a good idea. It's a common pattern that an object will implement a message <foo> which in turn will test if its delegate implements <foo> and if so, call it, and if not, do nothing or some default behaviour. If the delegate is self this will immediately enter an infinite loop (and it seems rare that an object will also test if delegate == self in these cases).


If you are subclassing the IKImageView, you have only to override the methods you're interested in. There's no need to set the delegate to self, it's not going to tell you anything different from what your subclass can find out directly. By the definition of the delegate pattern the delegate is *another object* that assists yours. If it's the same object it's not a delegate. (You don't keep a dog and bark yourself).

WAYTTD?

--Graham




_______________________________________________

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: IKImageView selection issue
      • From: Christian Graus <email@hidden>
References: 
 >IKImageView selection issue (From: Christian Graus <email@hidden>)

  • Prev by Date: More info - drag and drop could be the issue....
  • Next by Date: Re: IKImageView selection issue
  • Previous by thread: IKImageView selection issue
  • Next by thread: Re: IKImageView selection issue
  • Index(es):
    • Date
    • Thread