使用数据从 XIB 过渡到 Storyboard
Transition from XIB to Storyboard with data
所以我找到了一个如何从 XIB 过渡到故事板的示例
NSString * storyboardName = @"CheckoutStoryboard";
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle: nil];
UIViewController * vc = [storyboard instantiateViewControllerWithIdentifier:@"Checkout"];
[self presentViewController:vc animated:YES completion:nil];
这很好用,然后如果我需要在故事板场景之间传输数据,我可以使用此代码在第一个场景中使用此代码在 segue 之间传输数据。
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.destinationViewController respondsToSelector:@selector(setMyData:)]) {
[segue.destinationViewController performSelector:@selector(setMyData:)withObject:myObject];
}
}
第二次是这个
@property (nonatomic, strong) NSString *myData;
但是我无法弄清楚如何从我的 XIB 转换到我的带有数据的故事板。我的 XIB 上基本上有大量变量,我需要在我的故事板上使用这些变量,然后这些变量会被传递。除了将数据从 XIB 传递到故事板之外,我知道如何执行每一步。有什么想法吗?
我无法为您提供任何实际代码,但您没有在上述代码中使用 segues。
在您提供的示例中,您正在创建要显示的 UIViewController 实例,然后以模态方式呈现该视图控制器。
您只需直接从所需的视图控制器实例访问变量。
MyCustomUIViewControllerClass * vc = [storyboard instantiateViewControllerWithIdentifier:@"Checkout"];
vc.myData = <valueHere>
[self presentViewController:vc animated:YES completion:nil];
所以我找到了一个如何从 XIB 过渡到故事板的示例
NSString * storyboardName = @"CheckoutStoryboard";
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle: nil];
UIViewController * vc = [storyboard instantiateViewControllerWithIdentifier:@"Checkout"];
[self presentViewController:vc animated:YES completion:nil];
这很好用,然后如果我需要在故事板场景之间传输数据,我可以使用此代码在第一个场景中使用此代码在 segue 之间传输数据。
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.destinationViewController respondsToSelector:@selector(setMyData:)]) {
[segue.destinationViewController performSelector:@selector(setMyData:)withObject:myObject];
}
}
第二次是这个
@property (nonatomic, strong) NSString *myData;
但是我无法弄清楚如何从我的 XIB 转换到我的带有数据的故事板。我的 XIB 上基本上有大量变量,我需要在我的故事板上使用这些变量,然后这些变量会被传递。除了将数据从 XIB 传递到故事板之外,我知道如何执行每一步。有什么想法吗?
我无法为您提供任何实际代码,但您没有在上述代码中使用 segues。 在您提供的示例中,您正在创建要显示的 UIViewController 实例,然后以模态方式呈现该视图控制器。
您只需直接从所需的视图控制器实例访问变量。
MyCustomUIViewControllerClass * vc = [storyboard instantiateViewControllerWithIdentifier:@"Checkout"];
vc.myData = <valueHere>
[self presentViewController:vc animated:YES completion:nil];