Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/114.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何在Xcode中将数据传递到另一个故事板?_Iphone_Ios_Xcode_Xcode4.2_Uistoryboard - Fatal编程技术网

Iphone 如何在Xcode中将数据传递到另一个故事板?

Iphone 如何在Xcode中将数据传递到另一个故事板?,iphone,ios,xcode,xcode4.2,uistoryboard,Iphone,Ios,Xcode,Xcode4.2,Uistoryboard,在iPhone应用程序中,如何将数据从一个视图(xib文件)传递到另一个情节提要 比如说, 我有“welcome.xib”,其中包含nameTextfield和nextButton,用户将在nameTextfield中键入他们的姓名,然后单击next 应用程序将导航到“main.storyboard”,并在“main.storyboard”中的userNameLabel上显示nameTextfield.text中的文本 到目前为止我所知道的: 我知道如何在视图之间传递数据(从一个xib文件到另

在iPhone应用程序中,如何将数据从一个视图(xib文件)传递到另一个情节提要

比如说,

我有“welcome.xib”,其中包含nameTextfield和nextButton,用户将在nameTextfield中键入他们的姓名,然后单击next

应用程序将导航到“main.storyboard”,并在“main.storyboard”中的userNameLabel上显示nameTextfield.text中的文本

到目前为止我所知道的:


  • 我知道如何在视图之间传递数据(从一个xib文件到另一个xib文件)
  • 我知道如何从视图(xib文件)导航到另一个故事板

覆盖要从中传递信息的ViewController中的-prepareforsgue:sender:方法

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    DetailViewController *sc = [segue destinationViewController];
    // Here you can set variables in detailViewController. For example if you had a NSString called name
    sc.name = @"name_here";
    // Or you could do
    [sc setName:@"name_here"];
}

Swift 4.2+

将其添加到要从中发送数据的视图控制器-

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        guard
            let destination = segue.destination as? viewControllerName
            else {
                return
        }
        destination.variable =data
    }
确保变量的名称与要向其中发送数据的名称相同,viewControllerName也应完全相同

然后使用以下命令在按钮单击或任何completionHandler内执行操作-

self.performSegue(withIdentifier: "viewControllerIdentifierName", sender: nil)

还必须确保连接两个脚本的脚本的标识符名称与您在withIdentifier中键入的标识符名称相同,否则应用程序将崩溃。

“我知道如何在视图之间传递数据(从一个xib文件到另一个xib文件)”。。。那么你的问题是什么?似乎您已经知道答案。如果您正在使用故事板,为什么要为welcome view控制器创建单独的xib,而不是将其作为main.storyboard的一部分?