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

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


  • Follow-Ups:
    • Re: Accessing IBOutlet From non-IBAction Method
      • From: Camillo Lugaresi <email@hidden>
    • Re: Accessing IBOutlet From non-IBAction Method
      • From: James Spencer <email@hidden>
  • Prev by Date: Re: why does this leak?
  • Next by Date: Re: Class Memory Management
  • Previous by thread: Orange County Cocoa-heads conflicts with major holiday, film at 11!
  • Next by thread: Re: Accessing IBOutlet From non-IBAction Method
  • Index(es):
    • Date
    • Thread