NSWindow closes immediately after opening

Discussion in 'Mac Programming' started by BadWolf13, Apr 26, 2014.

  1. BadWolf13 macrumors 6502

    Joined:
    Dec 17, 2009
    #1
    I've got an issue in a program that uses multiple windows and multiple XIB files. I'm pretty sure this has something to do with ARC, since I used the same code for similar programs back in the days of Garbage Collection, and it worked.

    Basically, I create and initialize an instance of my NSWindowController subclass like so:

    Code:
            CLProjectWindowController *__strong newWindowController = [[CLProjectWindowController alloc] initWithProject:selectedProject inManagedObjectContext:_managedObjectContext];
            [windowControllers addObject:newWindowController];       
    And I created a custom initializer in my custom window controller that goes like this:

    Code:
    - (id)initWithProject:(CLProject *)aProject inManagedObjectContext:(NSManagedObjectContext *)moc {
    	if (!(self = [super initWithWindowNibName:@"Project"])) return nil;
        [self setProject:aProject];
        [self setManagedObjectContext:moc];
        
        [self showWindow:self];
    
        return self;
    }
    As I said above, I'm sure this has something to do with ARC since similar code worked perfectly fine before ARC was implemented. It's probably a weak reference somewhere, but I'm just not sure where. I declared my window controller array as __strong, but that didn't change anything. Is there any way in the debugging process to see what references, and how many, an object has? Anyone got any ideas where the weak reference is?
     
  2. BadWolf13 thread starter macrumors 6502

    Joined:
    Dec 17, 2009
    #2
    Ok, I feel silly now. I just added

    Code:
        windowControllers = [[NSMutableArray alloc] init];
    
    to the init method of my AppDelegate, and it works just fine now.
     

Share This Page