Passing data between view controllers in IOS

2019-01-29 12:58发布

问题:

I currently have a table view controller filled with data.

This table view controller leads to a Display view controller which displays the info with the selected data.

I've used a prepareForSegue to send the selected data to the next view controller.

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
    if ([[segue identifier] isEqualToString:@"showInfo"]) {


        NSManagedObject *selectedData = [self.datas objectAtIndex:[[self.tableView indexPathForSelectedRow] row]];
        DisplayInfoViewController *destViewController = segue.destinationViewController;
        destViewController.data = selectedData;
    }
}

My problem is that now I've added another view controller (Display More Info View Controller) after that view controller.

tableVC > DisplayVC >DisplayMoreInfoVC

I am having problems passing the same selected data over into the next view controller as my first prepareForSegue gets the selected data from the selected row of the table which i cannot access in the DisplayVC.

Any ideas?

回答1:

Why are you query the database in the dispayVC Are you passing the same data that you received from tableVC to DisplayMoreInfoViewController? If yes then you can just do

 DisplayMoreInfoViewController *destViewController = segue.destinationViewController;
 destViewController.data = self.data

If it is different the exlplain a little bite more what is

[self.database getdatapassedpreviously];