-1

To avoid marking this question as duplicate: I have seen this question (Passing Data between View Controllers) but that is for iOS. I have seen many other similar questions, but they all provide answers for IOS. My question is for OS-X app.

And yes, I did check and here and on Google, but I was unable to find anything that solves this issue in OS-X.

Having that said, here is the question:

In one of my NSViewControllers (MasterTableViewController) I have the following method:

- (IBAction)tableViewDoubleClick:(id)sender {

    NSInteger rowNumber = [_websitesTableView clickedRow];
    NSTableColumn *column = [_websitesTableView tableColumnWithIdentifier:@"websiteUrl"];
    NSCell *cell = [column dataCellForRow:rowNumber];
    NSString *cellValue = [cell stringValue];

}

How I could (should) properly pass this data (rowNumber, cellValue) to another NSViewController (DetailViewController)?

Community
  • 1
  • 1
user2417624
  • 653
  • 10
  • 32
  • 1
    What makes you think that none of the answers for iOS are applicable to OSx? – Hot Licks Aug 22 '15 at 17:41
  • I can't call [self pushViewController:viewControllerB animated:YES]; in OSX...I read all the answers there, and there is no answer for os-x. there is no pushViewController method in os-x. There are Segue's now in os-x but I use .xib files. If you can find solution there, can you please point it out, since I readed all answers there, 2 times, and found nothing helpful. – user2417624 Aug 22 '15 at 17:49
  • So that's only one of about 20 answers. – Hot Licks Aug 22 '15 at 17:52
  • Do you expect me to give you a reason for each separate answer why it is not applicable in os-x? If I find a solution there, why would I ask here? If you think that on that page there is an answer for my question, can you please tell me which one it is? – user2417624 Aug 22 '15 at 17:57
  • 1
    Think about it: You are asking "How do I share data in an application?" This is a very fundamental question, and if you don't intuitively know some answers (though perhaps not the "optimal" ones) then you should stop and spend some more time learning how to program. – Hot Licks Aug 22 '15 at 18:04
  • If you are willing to share your knowledge please post your solution here. I will appreciate it. – user2417624 Aug 22 '15 at 18:46
  • Few people will give you a quick solution. I won't, either. But see what you find in sharing data between NSWindowController. – El Tomato Aug 22 '15 at 22:33

1 Answers1

1

The higher-level answer is "don't". You're basically using a table cell (a UI item) as the data model for your next controller, which may work but is really error-prone when the app gets complicated.

You'd be better off with a real Data Model object that keeps track of the information you present in your cells. All the method you posted would then have to do is tell the Data Model which item was now the selected one and that same information would be available to the next controller when it appeared.

Phillip Mills
  • 30,888
  • 4
  • 42
  • 57
  • I have a tableview in one of the .xib files. User click on the row. I want to know which row has been clicked, and then to open new .xib files, and I need that data in the newly loaded .xib file. Can you give me any idea how can I do this? – user2417624 Aug 22 '15 at 17:54