简体   繁体   English

在不使用Segue的情况下将数据从一个视图控制器传递到另一个

[英]Passing data from one view controller to another without using Segue

I have a UITableView (let's say class “Parent” which is in view "screen 1"). 我有一个UITableView (假设类“ Parent”在视图“屏幕1”中)。 When I click on one of the Parent's cell's, I'm displaying another UITableView (let's call it class “child” in view “Screen2”). 当我单击“父级”单元格中的一个时,正在显示另一个UITableView (在“ Screen2”视图中将其称为“子级”类)。 Parent and child are connected through “segue” and I'm able to pass the data using “segue”. 父母和孩子通过“ segue”连接, 我可以使用“ segue”传递数据。

For example, parent is having cell – “Cell1” and on touch “Cell1”, I'm getting “Cell11”,”Cell12”,”Cell13” [this is “ screen2 , table view object”]. 例如,父母有一个单元格“ Cell1”,触摸“ Cell1”,我得到“ Cell11”,“ Cell12”,“ Cell13” [这是“ screen2 ,表视图对象”]。

Now, there are some descriptions associated with “Cell11” (Once I touched “Cell11”) and i'd like it to display Cell11's description in another view controller (“ screen3 ”). 现在,有一些与“ Cell11”相关的描述(一旦我触摸了“ Cell11”),我希望它在另一个视图控制器(“ screen3 ”)中显示Cell11的描述。 Here, to pass information between “screen2” to “screen3” I'd rather not to use a “Segue” . 在这里, 为了在“ screen2”到“ screen3”之间传递信息,我宁愿不使用“ Segue”

How can I do this? 我怎样才能做到这一点?

There are two ways in which you can present a new screen. 您可以通过两种方式显示新屏幕。

1) with the interface builder, here you use a segue to pass something onto the new screen. 1)使用界面生成器,在这里您可以使用segue将内容传递到新屏幕上。

2) manually instantiating it, after it is instantiated you can just present it. 2)手动实例化它,实例化之后就可以展示它。

Considering you do not want to use method 1, you can use method two like this: 考虑到您不想使用方法1,可以使用如下方法2:

ScreenBClass *screenB = [self.storyboard instantiateViewControllerWithIdentifier:@"screenB"];

screenB.objectPointerInOtherClass = self.objectIWantToPass;

[self screenB animated:YES];

暂无
暂无

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

相关问题 将数据从一个视图控制器传递到下一个视图控制器,而无需快速进行选择 - Pass data from one view controller to the next WITHOUT a segue in swift 我正在尝试通过“准备转场”将数据从一个视图控制器传递到另一个视图控制器,但它崩溃了 - I am trying to pass data from one View Controller to another in Swift via 'prepare for segue' but it crashes 演示过程中尝试在&lt;**&gt;上演示&lt;**&gt;。 在使用swift从一个视图控制器到另一个视图控制器执行segue的同时 - Attempting to present <**> on <**> while a presentation is in progress. While performing a segue from one view controller to another using swift 使用segue将NSMutableArray字典数据传递到另一个视图 - Passing NSMutableArray dictionary data to another view using segue 如何在视图控制器之间传递数据而不在 ios 中使用 segue? - How to pas data between view controller without using segue in ios? 使用segue将Int从一个ViewController传递到另一个 - passing an Int from one ViewController to another using a segue 将数据从 CollectionVewCell 传递到另一个视图 controller - Passing data from CollectionVewCell to another view controller 在iPhone中从一个视图弹出到另一个视图控制器时传递数据的问题 - problem in passing data when pop from one view to another view controller in iphone 如何使用自定义UITableViewCell进行筛选? 将数据传递到详细视图控制器的问题 - How to Segue using Custom UITableViewCell? Problems with passing data to the detail view controller 如何使用Segue将数据从一个屏幕传递到另一屏幕 - how to pass data from one screen to another screen using Segue
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM