[英]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.