1

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.

pkamb
  • 33,281
  • 23
  • 160
  • 191
Nik
  • 2,913
  • 7
  • 40
  • 66

1 Answers1

2

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.

paulmelnikow
  • 16,895
  • 8
  • 63
  • 114
  • I tried this but the compiler says that selectedRowDict not found on object type NSWindow. And for me to understand... It makes sense as this variable is declared in a separate NSObject class which is associated with the table delegate and the sheet. I have added some more information in the question.. t help solve the issue – Nik Nov 13 '12 at 10:44
  • Declare accountSheet with the type of your NSWindow subclass instead of NSWindow. That should satisfy the compiler. – paulmelnikow Nov 13 '12 at 14:35
  • I am still not getting your approach.. Sorry... Can you please elaborate on what you mean by 'Declare accountSheet with the type of your NSWindow subclass instead of NSWindow'. Because I have a nib for sheet and a object class which extends NSObject – Nik Nov 13 '12 at 16:53
  • I was mistaken – I thought your tableview delegate was a window subclass. Which class implements `-tableViewSelectionDidChange`? Is that your controller class which extends NSObject? – paulmelnikow Nov 13 '12 at 18:19
  • Yes... the code goes something like this - @interface Account_Sheet : NSObject – Nik Nov 13 '12 at 21:15
  • Alright. So, add an outlet to Account_Sheet – that's your controller class – for the table view, and connect the table view to that outlet in the nib. If the outlet doesn't show up, change the class on the File Owner placeholder from NSObject to Account_Sheet. Then, in `-sheetDidEnd:...`, use self.tableView.selectedRow and the code you already have to get the value you're looking for. – paulmelnikow Nov 14 '12 at 15:17
  • I followed your first approach - 'Declare accountSheet with the type of your NSWindow subclass instead of NSWindow. That should satisfy the compiler. ' and that worked thank you . Raj – Nik Nov 15 '12 at 15:34