• 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: TableView crash with Delegate
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: TableView crash with Delegate


  • Subject: Re: TableView crash with Delegate
  • From: "Gerriet M. Denkmann" <email@hidden>
  • Date: Tue, 14 Jun 2016 18:26:35 +0700

> On 14 Jun 2016, at 16:03, Alastair Houghton <email@hidden> wrote:
>
> On 14 Jun 2016, at 05:33, Gerriet M. Denkmann <email@hidden> wrote:
>>
>> But I had:
>> - (void)awakeFromNib
>> {
>> 	self.someUniqueObject = [ [ UniqueObject alloc ] init ];
>> }
>>
>> The problem: awakeFromNib gets called twice: once before applicationDidFinishLaunching:, once after.
>> This obviously created a total mess.
>
> It’s worth highlighting this, actually; -awakeFromNib gets called for the “File’s Owner” object in the nib file, which means if your object has multiple nib files associated with it, it can get called many times.  It’s best (IMO) to always write your -awakeFromNib methods with that in mind (though the documentation recommends trying to maintain a 1:1 correspondence between owners and nib files).

There is just one nib file, owned by (“File’s Owner”) NSApplication.
It contains (among other things) an AppDelegate, referenced as “File’s Owner”.delegate and a (view based) TableView.

AppDelegate is not the “File’s Owner” of any nib.

awakeFromNib in AppDelegate is first called (as one of the topLevelObjects in the nib) via:
NSApplicationMain → … loadNib … → [NSSet makeObjectsPerform:]

After applicationDidFinishLaunching awakeFromNib is called again, this time via:
NSApplicationMain → [NSApplication run] → [NSWindow layoutIfNeeded] … → [NSTableView layout] …→[NSTableRowData unarchiveView…] → [NSNib instantiateWithOwner] …

The documentation says: “You might also want to implement [awakeFromNib] for any other classes you instantiate directly in your nib file“, which probably means the topLevelObjects, like my AppDelegate.

But it does not mention whether these topLevelObjects get awakeFromNib sent only once or not.

But no problem, as long one keeps in mind (as you recommended) that awakeFromNib “can get called many times”.


Kind regards,

Gerriet.


_______________________________________________

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: TableView crash with Delegate
      • From: Jonathan Mitchell <email@hidden>
References: 
 >TableView crash with Delegate (From: "Gerriet M. Denkmann" <email@hidden>)
 >Re: TableView crash with Delegate (From: "Gerriet M. Denkmann" <email@hidden>)
 >Re: TableView crash with Delegate (From: Alastair Houghton <email@hidden>)

  • Prev by Date: Re: DNS resolution for apps vs Terminal?
  • Next by Date: Re: TableView crash with Delegate
  • Previous by thread: Re: TableView crash with Delegate
  • Next by thread: Re: TableView crash with Delegate
  • Index(es):
    • Date
    • Thread