Opening modal sheets from 10.9

I have an application that uses several Modal Sheets to enter data. The modal sheet opening methods worked fine and still work fine, but they are deprecated and I fear that they will not work with future versions of Xcode soon. Here Apple points out how to use modal sheets ,

    - (void)showCustomSheet: (NSWindow *)window

// User has asked to see the custom display. Display it.
{
    if (!myCustomSheet)
//Check the myCustomSheet instance variable to make sure the custom sheet does not already exist.
        [NSBundle loadNibNamed: @"MyCustomSheet" owner: self];

    [NSApp beginSheet: myCustomSheet
            modalForWindow: window
            modalDelegate: self
            didEndSelector: @selector(didEndSheet:returnCode:contextInfo:)
            contextInfo: nil];

    // Sheet is up here.
    // Return processing to the event loop
}

but with the release of Xcode 5.1, they identify that the loadNibNamed method is deprecated and that we should use a similar function that references top-level objects.

The problem I am facing changes this:

[NSBundle loadNibNamed:@"OrderDetailsWindow" owner:self];

.

NSArray *array;
[[NSBundle mainBundle]loadNibNamed:@"OrderDetailsWindow" owner:self topLevelObjects:&array]; 

This method call actually opens a modal sheet. However, at the end of my method, which opens a modal sheet, Xcode hangs up with this error.

0x7fff8c33b097:  andl   24(%r11), %r10d    Thread1: EXC_BAD_ACCESS (code:EXC_I386_GPFLT)

, . . , topLevelObjects ? , ? !

+4
2

, Apple - . "-" 2009 .

, , NIB.

loadNibNamed:owner:topLevelObjects:

, cocoa ; IBOutlets , nib .

.

NSArray, . , , NSArray , , .

NIB Window Controller, NSArray - Window Controller, , . , myCustomSheet NIB.

, [NSApp beginSheet:] , beginSheet NSWindow.

+4

NSWindowController :

, :

_myModalController = [[MyModalController alloc] init];
_myModalController.delegate = self;
[_myModalController beginSheet:self.window];

:

- (id)init {
    self = [super initWithWindowNibName:@"MyModalWindow" owner:self];
    return self;
}

- (void)beginSheet:(NSWindow *)mainWindow {
    [NSApp beginSheet:[self window]
       modalForWindow:mainWindow
        modalDelegate:self
       didEndSelector:@selector(_didEndSheet:returnCode:contextInfo:)
          contextInfo:nil];
}

- (void)endSheet:(NSWindow *)mainWindow {
    [NSApp endSheet:[self window]];
    [[self window] orderOut:mainWindow];
}

, loadNibNamed: .

0

All Articles