[英]how to pass data from one screen to another screen using Segue
I have 2 views A and B. View A contains a table of 1 section with 2 rows. 我有2个视图A和B。视图A包含一个包含2行的1节表。 Each row has each own picture....My task is how to display in view B a picture of row 1 when you click on row one.
每行都有自己的图片....我的任务是如何在视图B中单击第一行时显示第一行的图片。 If you click on row 2, view B will display picture of row 2. Please show me the way to pass data from one to another view using seque.
如果单击第2行,则视图B将显示第2行的图片。请告诉我使用seque将数据从一个视图传递到另一视图的方法。
Say you have controllers ViewControllerA and ViewControllerB for the two views and also assuming that you have created a segue between the views in storyboard with an identifier 假设您有两个视图的控制器ViewControllerA和ViewControllerB,并且还假设您已在情节提要中的视图之间创建了带有标识符的序列
ViewControllerA should implement this method ViewControllerA应该实现此方法
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if (segue.identifier.length > 0)
{
if ([segue.identifier isEqualToString:@"your_identifier_name"])
{
ViewControllerB *viewControllerB = (ViewControllerB *)segue.destinationViewController;
//And you can pass data between the two controller.
viewControllerB.currentRow = self.selectedRow;
}
}
}
jajo87's answer will work, but if you're asking, you don't have a full grasp on MVC design. jajo87的答案会起作用,但是如果您提出要求,您可能对MVC设计并不完全了解。 Both ViewControllers should be pulling the images from a single model (a custom subclass of NSObject in a file you create with command-N).
两个ViewController都应从单个模型(使用Command-N创建的文件中NSObject的自定义子类)中提取图像。 That model should have a property that represents the image you picked.
该模型应具有代表您选择的图像的属性。 Both ViewControllers can have pointers to the model;
两个ViewController都可以具有指向模型的指针; pass them along when you instantiate ViewController B.
实例化ViewController B时将它们传递给它们。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.