how to get information from custom sheet in OSX

228 views Asked by At

I have created a custom sheet which has a table in it. The table has list of usernames in it:

custom sheet with usernames

I want to get the selected row value and use it in the application. I am able to get the row in the the following way:

-(void)tableViewSelectionDidChange:(NSNotification *)notification{
    NSInteger selectedRow = [[notification object] selectedRow];
    if(selectedRow != -1){
        self.selectedRowDict = [self.usersArray objectAtIndex:selectedRow];
    }
}

But now my issue is that I want to pass the data back to the main window which started this sheet.

The following is the code for the same:

if(!self.accountSheet){
    [NSBundle loadNibNamed:@"AccountSheet" owner:self];
}
[NSApp beginSheet:self.accountSheet
   modalForWindow:[mainWindowView window]
    modalDelegate:self
   didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:)
      contextInfo:NULL];

How to do this?

Please note: The sheet is created in a separate nib from the main window nib. Each nib have their own NSObject extended class to implement the actions and other window related work. the sheet nib is related to the main window as file owner and has a IBOutlet in main nib NSObject class

If any more information is needed please let me know.

1

There are 1 answers

7
paulmelnikow On

Have your sheet store the information in an instance variable, like you're doing, and then in your didEndSelector, just get the values from the sheet: self.accountSheet.selectedRowDict, or what-have-you.