iphone - 如何在 Xcode 中将数据传递到另一个 Storyboard?

标签 iphone ios xcode xcode4.2 uistoryboard

在 iPhone 应用程序中,如何将数据从一个 View (xib 文件)传递到另一个 Storyboard?

例如,

我有“welcome.xib”,其中包含 nameTextfield 和 nextButton ,用户将在 nameTextfield 中输入他们的名字并单击下一步

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

到目前为止我所知道的:

  • 我知道如何在 View 之间传递数据(从一个 xib 文件到另一个 xib 文件)
  • 我知道如何从 View (xib 文件)导航到另一个 Storyboard

最佳答案

重写您想要从中传递信息的 ViewController 中的 -prepareForSegue: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"];
}

关于iphone - 如何在 Xcode 中将数据传递到另一个 Storyboard?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9706678/

相关文章:

iphone - 我怎样才能让 NSTimer 在用户使用应用程序的整个过程中一直运行?

ios - UITouch-是否可以禁用多次点击

iphone - CAAnimation 在滚动出界时停止

ios - 在 Swift 3 中从 AudioBufferList 中提取数据

ios - 尽可能简单地发送 iMessage iOS

ios - 使用点击手势更改 UIView 的背景颜色(iOS)

objective-c - 在 iOS 中从 CoreData 获取数据的快速方法是什么?

ios - 如何将登录模块实现为我的 iOS 框架的一部分

ios - 在 Swift 中重写 UIButton 的 setEnabled 方法

ios - 新创建的Apple开发者帐户未显示应用