• 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
Encoding custom class from Interface Builder?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Encoding custom class from Interface Builder?


  • Subject: Encoding custom class from Interface Builder?
  • From: Peter Duniho <email@hidden>
  • Date: Wed, 4 Jul 2007 23:23:01 -0700

Please bear with me, I'm new to Cocoa, and it's been almost 15 years since I did any Mac development.

General scenario: I created a simple interface in IB, with a window and a custom view class, derived from NSView.

In that custom view class, I want to do some initialization. However, overriding the NSView initWithRect method doesn't work. I understand this is because the class was instantiated in IB, rather than at runtime, archived and then unarchived later at runtime.

The suggestion I found in the past messages on this mailing list is to override the awakeFromNib method, and do initialization there. That works, but now I've got initialization code called from two different places: initWithRect and awakeFromNib.

That somehow seems ungraceful to me, and it occurred to me that if I could just introduce my custom class members into the archive, then I could have my data unarchived along with the base class stuff. However, I'm having trouble getting this to work.

In particular, as near as I can tell, even though I implement encodeWithCoder and initWithCoder, only the latter gets called. It's hard for me to be sure, but I get an exception trying to unarchive a string instance in my class, and when I throw something extra like displaying an alert into the encodeWithCoder method, it never gets shown when I'm saving the nib in IB (which is where I'd expect my encodeWithCoder to be called).

Am I doing something wrong? Or is it simply a known limitation that a custom class used in IB does not actually get archived when saving from IB? Is awakeFromNib the only way to initialize a custom class used in IB, or is there actually some approved mechanism for allowing custom classes saved in the nib to be unarchived in a useful way?

Actually, given that my custom behavior (overridden drawing, for example) is not actually reflected in IB, I suppose it's possible that it's not really even using my class, except to refer to it by name in the nib. Frankly, that seems a bit broken to me, but it would explain what I'm seeing (or not seeing, as the case may be).

Thanks,
Pete
_______________________________________________

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: Encoding custom class from Interface Builder?
      • From: Stephane Sudre <email@hidden>
  • Prev by Date: Re: NSOutlineView validateDrop Flips Values
  • Next by Date: IP address validation
  • Previous by thread: NSPredicate problem: ANY attribute BETWEEN { 1, 10 }
  • Next by thread: Re: Encoding custom class from Interface Builder?
  • Index(es):
    • Date
    • Thread