Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3953416
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:58:20+00:00 2026-05-20T01:58:20+00:00

im very new in cocoa development and I’m trying to load a Window. I

  • 0

im very new in cocoa development and I’m trying to load a Window.
I will explain my problem.

When the user click the menuItem I use the following code to load my window

if ( !cadastroContasController )
{
    cadastroContasController = [[cadastroContas alloc]init];
    [cadastroContasController SetMenuItem:sender];
}
if ( ![[cadastroContasController window] isVisible] )
{
    NSLog(@"!isVisible");
    [cadastroContasController showWindow:nil];
}

I my cadastroContas class looks like this:

@interface cadastroContas : NSWindowController 
{
    NSMenuItem *mnuCommand;
    IBOutlet NSComboBox *cmbSelecao;
    IBOutlet NSTextField *txtNome;
    IBOutlet NSTextField *txtSaldoInicial;
    IBOutlet NSTextField *txtAnotacoes;
}


- (void)windowDidBecomeKey:(NSNotification *)notification;
- (BOOL)windowShouldClose:(id)sender;
- (void)windowWillClose:(NSNotification *)notification;
- (void)SetMenuItem:(NSMenuItem*) menu;
- (NSMenuItem*) MenuItem;

@end

and the implementation is

@implementation cadastroContas

-(void)windowDidLoad
{
NSLog(@"windowDidLoad");
[mnuCommand setState:NSOnState];
}

-(id)init
{
    self = [super initWithWindowNibName:@"cadastroContas"];
NSLog(@"Init self=%p", self);
return self;
}
-(void)dealloc
{
NSLog(@"Dealoc=%p", self);
[super dealloc];
}

- (void)windowDidBecomeKey:(NSNotification *)notification
{
NSLog(@"windowDidBecomeKey window=%p", [self window]);
}

- (BOOL)windowShouldClose:(id)sender
{
NSLog(@"windowShouldClose Window=%p", [self window]);
NSLog(@"mnuComando=%p GetMenuItem=%p", mnuCommand, [self MenuItem] );
if ( mnuCommand )
{
    [mnuCommand setState:NSOffState];
}
return YES;
}

- (void)windowWillClose:(NSNotification *)notification
{

NSLog(@"windowWillClose  Window=%p", [self window]);
NSLog(@"mnuCommand=%p GetMenuItem=%p", mnuCommand, [self MenuItem] );   
[self dealloc];
}

- (void)SetMenuItem:(NSMenuItem*) menu
{
mnuCommand = menu;
}

- (NSMenuItem*) MenuItem
{
    return mnuCommand;
}

@end

When the menu was clicked, I received two messages “Init” and I don’t know why.
Exemple:

[2223:a0f] Init self=0x10014fe40
[2223:a0f] Init self=0x10011f5a0

The second message let the “[cadastroContasController SetMenuItem:sender];” useless.

So, I need help to understand whats going on..

Another thing, [[cadastroContasController window] is always returning NULL(0x0)!!, but inside my controller i can handle it (it isn’t null).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T01:58:21+00:00Added an answer on May 20, 2026 at 1:58 am

    This means you inited two instances, as shown by your logging of the self pointer: Notice that the value is different between the two messages.

    You can use the Allocations instrument in Instruments to see what caused each window controller to be instantiated.

    Usually, this problem happens when you create one of these in the nib and the other one in code. In the case of a window controller, the one you create in code should be the owner of its nib; you should not create another window controller as an object in the nib.

    Another thing, [[cadastroContasController window] is always returning NULL(0x0)!!, but inside my controller i can handle it (it isn’t null).

    The window controller whose window outlet you set to the window is the one that is returning non-nil. The window controller whose window outlet you didn’t set is the one that is returning nil.

    Following from what I said above, after deleting the window controller you created in the nib, you should connect your File’s Owner’s window outlet to the window.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm VERY new to WPF, and still trying to wrap my head around binding
I am new to iPhone application development so that i want to learn cocoa
Very new to Iphone development here, I have a project which is successfully building
I am very new to stored procedures. I am trying to make a stored
I am very new to git but I need to use it for one
I am very new to Cocoa and Ojective-C. Learning as you go is my
First of all, I am a a very new Objective C/Cocoa iOS Developer but
Im very new to SQL but need to write a query to do the
Warning - I am very new to NHibernate. I know this question seems simple
I still very new using Subversion. Is it possible to have a working copy

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.