• 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: [iPhone] Why can't a UITextField be its own delegate?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [iPhone] Why can't a UITextField be its own delegate?


  • Subject: Re: [iPhone] Why can't a UITextField be its own delegate?
  • From: Luke the Hiesterman <email@hidden>
  • Date: Sat, 25 Jul 2009 17:35:46 -0700


On Jul 25, 2009, at 5:32 PM, Adam R. Maxwell wrote:


On Jul 25, 2009, at 5:02 PM, Luke the Hiesterman wrote:


On Jul 25, 2009, at 3:41 PM, Adam R. Maxwell wrote:

On Jul 25, 2009, at 3:23 PM, Kyle Sluder wrote:

Internally, UITextField is going to use self.delegate to get its
delegate, following the correct accessor behavior. You've gone and
replaced -delegate to return self. But the delegate pattern says that
messages which this object does not understand should be forwarded to
the delegate. This means that a class with a delegate needs to
implement -respondsToSelector: this way:


- (BOOL)respondsToSelector:(SEL)aSelector {
return [super respondsToSelector:aSelector]
|| [self.delegate respondsToSelector:aSelector];
}

Where is this guaranteed by the delegate pattern? I've created a fair number of classes with delegates and never done this; it would be interesting to know that I've been doing it wrong for years ;).

It's not guaranteed - it's just the right way to implement an optional delegate method.

Who says it's the right way, though? I've never seen a delegate implemented that way, in documentation or sample code, and wouldn't you also have to implement forwarding code to keep this from breaking? Maybe I'm dense, but I don't see the point of doing this.



I read the code too quickly. I just thought it was the standard if ([delegate respondsToSelector:....]) [delegate doSomething]; paradigm. I retract my statement. That is definitely not a standard of the delegation pattern.


Luke
_______________________________________________

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: [iPhone] Why can't a UITextField be its own delegate?
      • From: Kyle Sluder <email@hidden>
References: 
 >[iPhone] Why can't a UITextField be its own delegate? (From: WT <email@hidden>)
 >Re: [iPhone] Why can't a UITextField be its own delegate? (From: Brian Slick <email@hidden>)
 >Re: [iPhone] Why can't a UITextField be its own delegate? (From: WT <email@hidden>)
 >Re: [iPhone] Why can't a UITextField be its own delegate? (From: Luke the Hiesterman <email@hidden>)
 >Re: [iPhone] Why can't a UITextField be its own delegate? (From: WT <email@hidden>)
 >Re: [iPhone] Why can't a UITextField be its own delegate? (From: Kyle Sluder <email@hidden>)
 >Re: [iPhone] Why can't a UITextField be its own delegate? (From: WT <email@hidden>)
 >Re: [iPhone] Why can't a UITextField be its own delegate? (From: Kyle Sluder <email@hidden>)
 >Re: [iPhone] Why can't a UITextField be its own delegate? (From: "Adam R. Maxwell" <email@hidden>)
 >Re: [iPhone] Why can't a UITextField be its own delegate? (From: Luke the Hiesterman <email@hidden>)
 >Re: [iPhone] Why can't a UITextField be its own delegate? (From: "Adam R. Maxwell" <email@hidden>)

  • Prev by Date: Re: I need a milder application badge (solution)
  • Next by Date: Re: [iPhone] Why can't a UITextField be its own delegate?
  • Previous by thread: Re: [iPhone] Why can't a UITextField be its own delegate?
  • Next by thread: Re: [iPhone] Why can't a UITextField be its own delegate?
  • Index(es):
    • Date
    • Thread