• 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: Accessing IBOutlet From non-IBAction Method
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Accessing IBOutlet From non-IBAction Method


  • Subject: Re: Accessing IBOutlet From non-IBAction Method
  • From: James Spencer <email@hidden>
  • Date: Mon, 13 Feb 2006 19:40:55 -0600


On Feb 13, 2006, at 6:58 PM, haym37 wrote:

Whenever I attempt to access an IBOutlet from any method which is not an IBAction method or awakeFromNib, it does not work, and the retain count for the IBOutlet is 0.

Here is my code in the header (.h) file:

...

and here is my code in the main (.m) file:

#import "InspectorPanelController.h"
...
I am accessing ipcChangeState from another class like this:

	InspectorPanelController *ipc = [InspectorPanelController alloc];
	[ipc ipcChangeState];
	[ipc release];


You obviously haven't given us all of the relevant code but to guess at a couple of the biggest problems:


1) Presumably you are instantiating an inspector panel in your main nib as you haven't given us any code for loading the nib but your awakeFromNib is being called so presumably Cocoa is loading the nib. The question then is how are you connecting your inspectorPanel to the controller's IBOutlet? My guess would be that you have instantiated a controller in the nib as well as a panel, yes? If so, the controller you create in the third line from the bottom above (referenced by "ipc") is a completely different controller object from the one created in the nib and it is the latter object that contains the reference to the IBOutlet. ipc's outlet doesn't reference a panel and never did. (Thus your comment in your earlier email that the panel is being deallocated is not correct; the outlet was never set in the first place.) In the class that sends messages to the inspector panel controller, you need some kind of reference to the original. How to do that would depend on what the class trying to access the controller is doing.

2) An alternative way of instantiating a controller and a panel would be to do it as you have in the last of the code above (i.e. specifically allocate a controller) and then have it load a nib with the panel in it's initialization code, filling in the IBOutlet via the FileOwner. What you have done here has two massive problems however: a) you don't have any such initialization code to load the nib and b) even if you did, you don't call it. Note with regard to b) that even if you don't have an initialization method of your own, you would still have to call init at some point, e.g.

InspectorPanelController *ipc = [[InspectorPanelController alloc]init];

If you aren't understanding the difference between the controller object you are instantiating in the nib and the one you instantiate with alloc, you might want to get a good book on Objective C and Cocoa.

Spence

James P. Spencer
Rochester, MN

email@hidden

"Badges??  We don't need no stinkin badges!"

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Accessing IBOutlet From non-IBAction Method (From: haym37 <email@hidden>)

  • Prev by Date: Re: why does this leak?
  • Next by Date: Re: Accessing IBOutlet From non-IBAction Method
  • Previous by thread: Accessing IBOutlet From non-IBAction Method
  • Next by thread: Re: Accessing IBOutlet From non-IBAction Method
  • Index(es):
    • Date
    • Thread