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

查看:112
本文介绍了在IOS中的视图控制器之间传递数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有一个填充数据的表视图控制器。



这个表视图控制器导向显示视图控制器,显示所选数据的信息。 p>

我使用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;
}
}

我的问题是,



tableVC> DisplayVC> DisplayMoreInfoVC



由于我的第一个prepareForSegue从在DisplayVC中无法访问的表的所选行获取所选数据,所以将相同的选定数据传递到下一个视图控制器中有问题。



任何想法?

解决方案

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

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

如果不同,exlplain有点咬什么是

  [self.database getdatapassedpreviously]; 


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?

解决方案

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天全站免登陆