• 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: superclass and awakeFromNib
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: superclass and awakeFromNib


  • Subject: Re: superclass and awakeFromNib
  • From: Fritz Anderson <email@hidden>
  • Date: Sat, 30 Nov 2002 12:36:14 -0600

When -[DummyViewA awakeFromNib] is called with [aDummyViewB awakeFromNib], the "self" pointer still points to an instance of DummyViewB. Therefore [self superclass] will be DummyViewA.

Keep repeating to yourself: Objective-C messages are resolved at run time, not compile time.

"super," however, still refers to the implementation in the superclass of the current implementation, which is why your code attempts to send -[NSView awakeFromNib], and fails.

What you do know at compile time is what classes you're implementing awakeFromNib for, what the superclass of each class is, and that NSView does not implement awakeFromNib, It isn't cheating to simply send [super awakeFromNib] in -[DummyViewB awakeFromNib] and not send it in -[DummyViewA awakeFromNib].

-- F

On Saturday, November 30, 2002, at 10:52 AM, Simon Bovet wrote:

@interface DummyViewA : NSView {
}
@end

@interface DummyViewB : NSViewA {
}
@end

@implementation DummyViewA // same for DummyViewB

-(void)awakeFromNib
{
if ([[self superclass]
instancesRespondToSelector:@selector(awakeFromNib)])
[super awakeFromNib];
}

@end

When [DummyViewB awakeFromNib] is performed during program execution,
it works fine and calls [DummyViewA awakeFromNib]. Now, [self
superclass] in DummyViewA returns DummyViewA (!) and [super
awakeFromNib] throws the exception "*** -[DummyViewB awakeFromNib]:
selector not recognized".

--
Fritz Anderson - Consulting Programmer - Chicago, IL
Mail: <email@hidden>
Risumi: <http://resume.manoverboard.org>
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >superclass and awakeFromNib (From: Simon Bovet <email@hidden>)

  • Prev by Date: Re: Add Toolbar to Document Based Project
  • Next by Date: Re: Add Toolbar to Document Based Project
  • Previous by thread: superclass and awakeFromNib
  • Next by thread: Add Toolbar to Document Based Project
  • Index(es):
    • Date
    • Thread