简体   繁体   English

如何使用Segue将数据从一个屏幕传递到另一屏幕

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

相关问题 使用手机间隙将数据从iPhone的一个屏幕传递到另一屏幕 - Passing data from one screen to another screen in iPhone using phone gap 在不使用Segue的情况下将数据从一个视图控制器传递到另一个 - Passing data from one view controller to another without using Segue 我正在尝试通过“准备转场”将数据从一个视图控制器传递到另一个视图控制器,但它崩溃了 - I am trying to pass data from one View Controller to another in Swift via 'prepare for segue' but it crashes 单击后退按钮,ios后如何将数据从当前屏幕传回到上一屏幕 - how can pass data back from current screen to previous screen after clicking back button, ios 将数据从一个视图控制器传递到下一个视图控制器,而无需快速进行选择 - Pass data from one view controller to the next WITHOUT a segue in swift 在 web 应用程序中从一个屏幕滑动到另一个屏幕 - Sliding from one screen to another in a webapp 使用segue将Int从一个ViewController传递到另一个 - passing an Int from one ViewController to another using a segue Segue导致黑屏 - Segue lead to black screen 如何以编程方式从一个UIViewController切换到另一个,而无需模态或Push? - How to programmatic segue from one UIViewController to another without Modal or Push? iOS-使用xib中的tabBarController将数据从一个viewController传递到另一个 - iOS - Pass Data from one viewController to another using tabBarController in xib
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM