两个视图控制器之间的数据传输 [英] Data transfer between two view controller

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

问题描述

我非常坚持这个仪式现在让我用这种方式解释问题:

i m pretty stuck on this one rite now let me explain the problem this way:


  • 电机视图控制器(表1)

  • 添加新电机(表2)

  • 显示电机详细信息(视图1)

  • 编辑电机详细信息(表格) 3)
    现在发生的事情是我去表1然后点击添加按钮然后转到表2并在表1上添加新电机当我点击表1的行时我去查看1我的详细信息是显示在标签中,我点击此视图上的编辑按钮,当我在这里编辑时会弹出一个编辑屏幕我想将这些细节保存回我的视图1我该怎么做?(即时通讯使用故事板和所有视图通过segue's)(基本上我想做编辑功能所以当编辑屏幕出现我希望看到我的文本框中的现有细节n den我可以编辑dem n den将它们保存回来)谢谢

  • Motor View Controller (table 1)
  • Add New Motor (table 2)
  • show motor Detail (View 1)
  • edit Motor Detail (table 3) now what happens is i go to table 1 then click on add button then go to table 2 and add a new motor on table 1 when i click on row of table 1 i go to view 1 where my details are shown in the labels and wen i click the edit button on this view a edit screen pops up now when i edit here i wanna save these details back onto my view 1 how do i do it ?( im using storyboard and all views are connected through segue's ) (basically i want to do edit function so wen the the edit screen comes up i want to see the existing details in my text boxes n den i get to edit dem n den save them back)thank you

推荐答案

我有两个答案。


  1. 你需要永久存储您的数据。查看Apple的核心数据。他们有文档和一个例子。另请参阅 RayWenderLick的核心数据教程。答案是您将使用Core Data创建一个创建sql数据库的持久存储。该数据库将有一个电机实体。数据库的每个条目都包含一个电机的详细信息。每个视图控制器(表)都将访问数据库。

  1. You need a permanent store for your data. Check out Apple's Core Data. They have documentation and an example. Also see RayWenderLick's Tutorial on Core Data. The answer is you will use Core Data to create a persistent store creating an sql database. The database will have an entity for motors. Each entry for the database will contain the detail for one motor. Each view controller (table) will access the database.

此解决方案为您提供持久性存储。如果您再次打开手机电源,您仍然可以获得数据。

This solution provides you with a persistent store. If your power the phone off and on again you will still have your data.

快速解决方案是设置委托协议,允许编辑视图控制器将数据写回其他视图控制器之一。阅读了解基本设计模式

A quick solution is to setup a delegate protocol which would allow the edit view controller to write data back to one of the other view controllers. Read Understanding Fundamental Design Patterns.

此解决方案可能会让您解决您的问题,但不提供持久存储。

This solution may get you past your immediate problems but does not provide a persistent store.

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

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