Accessing IBOutlet From non-IBAction Method
Accessing IBOutlet From non-IBAction Method
- Subject: Accessing IBOutlet From non-IBAction Method
- From: haym37 <email@hidden>
- Date: Mon, 13 Feb 2006 19:58:16 -0500
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:
/* InspectorPanelController */
#import <Cocoa/Cocoa.h>
@interface InspectorPanelController : NSObject
{
IBOutlet NSPanel *inspectorPanel;
}
- (IBAction)changeState:(id)sender;
- (void)ipcChangeState;
@end
and here is my code in the main (.m) file:
#import "InspectorPanelController.h"
@implementation InspectorPanelController
- (void)awakeFromNib
{
NSLog(@"retain count awakefromnib: %d", [inspectorPanel retainCount]);
NSLog(@"title: %@", [inspectorPanel title]);
}
- (IBAction)changeState:(id)sender
{
NSLog(@"retain count changestate0: %d", [inspectorPanel retainCount]);
NSLog(@"inspectorpanel: %@", [inspectorPanel title]);
if ([inspectorPanel isVisible])
[inspectorPanel close];
else
[inspectorPanel orderFront:inspectorPanel];
NSLog(@"retain count changestate1: %d", [inspectorPanel retainCount]);
}
- (void)ipcChangeState
{
NSLog(@"retain count ipcchangestate: %d", [inspectorPanel
retainCount]);
NSLog(@"here");
NSLog(@"title: %@", [inspectorPanel title]);
}
- (void)dealloc
{
[super dealloc];
}
@end
I am accessing ipcChangeState from another class like this:
InspectorPanelController *ipc = [InspectorPanelController alloc];
[ipc ipcChangeState];
[ipc release];
It does in fact get inside the ipcChangeState method. However, this
is the output in the log:
retain count awakefromnib: 2
title: Inspector
retain count ipcchangestate: 0
here
title: (null)
retain count changestate0: 1
inspectorpanel: Inspector
retain count changestate1: 2
retain count changestate0: 1
inspectorpanel: Inspector
retain count changestate1: 1
How come it cannot access inspectorPanel from ipcChangeState?
_______________________________________________
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