• 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: How to get my class instance that's in IB
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to get my class instance that's in IB


  • Subject: Re: How to get my class instance that's in IB
  • From: Jonathan Hess <email@hidden>
  • Date: Wed, 20 Feb 2008 18:58:51 -0800

Hey Russ -

It sounds like you have some objects that are already alive before you load the nib, and then you load the nib, and you want these previously living objects to be able to refer to the objects that were created when the NIB was loaded. To do this, you should load the nib with [NSBundle loadNibNamed:owner:] and pass in an object for the owner. Then in your nib file, the "File's Owner" object will present the instance you pass in to [NSBundle loadNibNamed:owner:] at runtime.

Here's come code composed in the mail editor:
@interface MyController : NSObject {
	IBOutlet id object;
}
@end

@implementation MyController
- (void)loadNib {
	[NSBundle loadNibNamed:@"MyNibFile" owner:self];
        NSLog(@"Object is %@" object);
}
@end

MyNibFile.nib should be an a NIB where the File's Owner has its class set to "MyController" and it's 'object' outlet connected to the object you want to refer to.

Jon Hess


On Feb 20, 2008, at 6:23 PM, Russ McBride wrote:


I'm embarrassed to ask this question. Seems like it should be simple but I really don't know the answer.


When I instantiate one of my classes by (in Leopard) dragging an object icon from the library window over to the MainMenu.nib and selecting the name of my class from the inspector window an instance of my class is created (right?). I know because I can now then see the NSLog statements for init method of that class showing up in the console.

But if there's an instance of my class then I should be able to call a method on that instance without having to make a new instance. But how do I get ahold of that IB-created instance of my class so that I can call one of its methods??

I know I can do this to get ahold of my class through the bundle:

NSBundle *b = [NSBundle mainBundle];
Class myClass = [b classNamed:@"MySpecialClass];

But this doesn't give me the instance.

??






_______________________________________________

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: 
 >How to get my class instance that's in IB (From: Russ McBride <email@hidden>)

  • Prev by Date: Re: How to get my class instance that's in IB
  • Next by Date: Re: How to get my class instance that's in IB
  • Previous by thread: Re: How to get my class instance that's in IB
  • Next by thread: Re: How to get my class instance that's in IB
  • Index(es):
    • Date
    • Thread