在 IOS 中的视图控制器之间传递数据 [英] Passing data between view controllers in IOS

查看:22
本文介绍了在 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.

我使用 prepareForSegue 将选定的数据发送到下一个视图控制器.

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

tableVC > DisplayVC >DisplayMoreInfoVC

我在将相同的选定数据传递到下一个视图控制器时遇到问题,因为我的第一个 prepareForSegue 从我无法在 DisplayVC 中访问的表的选定行中获取选定的数据.

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.

有什么想法吗?

推荐答案

为什么要在 dispayVC 中查询数据库 你是否将从 tableVC 接收到的相同数据传递给 DisplayMoreInfoViewController?如果是,那么你可以做

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]; 

这篇关于在 IOS 中的视图控制器之间传递数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆