• 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: Get specified window from nib
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Get specified window from nib


  • Subject: Re: Get specified window from nib
  • From: Jonathan Hess <email@hidden>
  • Date: Tue, 12 Aug 2008 11:28:03 -0700


On Aug 12, 2008, at 3:33 AM, Andy Lee wrote:

On Aug 10, 2008, at 10:07 PM, Graham Perks wrote:
On Aug 10, 2008, at 9:01 PM, Fosse wrote:

I have one nib containing more than ten dialogs and want to get the
specified window after nib is loading..

Perhaps NSNib's instantiateNibWithOwner:(id)owner topLevelObjects: (NSArray **)topLevelObjects ? You'll get an array of top level objects, which will presumably contain your dialogs... If it were me I'd just join them up in IB. You only need to do it once.


Graham.

What did you think of Graham Perks's suggestion to use NSNib to load the nib file?


I haven't used NSNib myself -- only glanced at the docs -- but I believe it's the only way to get your program to know about the names you assigned your windows in IB. So if you rely on those names to pick the one you want, you're going to be stuck retyping them somewhere anyway, whether to make them into outlets or some other place.

NSNib, along with NSBundle will both let you load a NIB and will return the top level objects. Neither of these methods will let you access the objects by 'name' though. The name in Interface Builder is only for you to label the objects. As others have pointed out, accessing an object by name is what an outlet is for. It effectively is accessing by name but it removes all almost all of the risk of having string constants get out of date.


The correct way to accomplish this is with an outlet from the file's owner. Using outlets is less error prone than having to syncing up two sets of string constants. It would probably be best to put the related windows in one nib file each so that you can cut down the number of objects in each NIB. Right now, when the giant NIB file is loaded, every single window in your application is created. Also, by putting the windows all together in one nib, you won't be able to instantiate multiple copies of any of the windows without instantiating the whole batch.

You probably wouldn't want to work with hundreds of classes in one source file. For the same reasons, you should strive to have smaller, more focused nib files.

If you think about it, the string constant isn't really that different from an outlet -
Jon Hess






If there's some other attribute of the window you can use to select them, like a unique window title, one possibility is to scan the window list. See the NSWindowList() function. This assumes you only load the nib once and the window names are unique application- wide and they never change.

--Andy


_______________________________________________

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

_______________________________________________

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


References: 
 >Get specified window from nib (From: Fosse <email@hidden>)
 >Re: Get specified window from nib (From: Graham Perks <email@hidden>)
 >Re: Get specified window from nib (From: Andy Lee <email@hidden>)

  • Prev by Date: I don't understand why this is leaking...
  • Next by Date: Re: NSImage and zooming PDFs vs. bitmaps
  • Previous by thread: Re: Get specified window from nib
  • Next by thread: Re: Get specified window from nib
  • Index(es):
    • Date
    • Thread