简体   繁体   English

在IOS中的视图控制器之间传递数据

[英]Passing data between view controllers in IOS

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. 我使用了prepareForSegue将选定的数据发送到下一个视图控制器。

- (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 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. 我在将相同的选定数据传递到下一个视图控制器时遇到问题,因为我的第一个prepareForSegue从表的选定行中获取了选定数据,而我在DisplayVC中无法访问该表。

Any ideas? 有任何想法吗?

Why are you query the database in the dispayVC Are you passing the same data that you received from tableVC to DisplayMoreInfoViewController? 为什么要在dispayVC中查询数据库?您是否将从tableVC接收到的数据传递给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 如果不同,则exlplain多咬一点是什么

[self.database getdatapassedpreviously]; 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM