我有两个问题。
<强>1。第一个问题:
在我的项目中,我有两个不同的 Storyboard文件:A storyboard
和 B storyboard
.
我想从 nsstring
传递数据 ( (A) controller of (A) storyboard
)至 (B) controller of (B) storyboard
我是怎么做到的?
<强>2。第二个问题:
在第二个 Storyboard中,我有两个用 segue 链接的 Controller 。
当我用这条指令在代码中调用 segue 时:
[self.navigation controller performSegueWithIdentifier: @"secondViewSegue" sender:self];
我有一条消息:"has no segue with identifier 'secondViewSegue' "
为什么?
最佳答案
1/一个好的方法是制作一个单独的模型对象,可以从两个位置同等地寻址。最简单的方法 是将属性添加到 AppDelegate.h
文件的 @interface
部分,例如
@property (nonatomic, strong) NSString* sharedString;
要设置和获取它,您需要在任何需要它的文件中添加对 AppDelegate 的类型化访问:
#include AppDelegate.h
然后你可以使用...
AppDelegate* appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
//to set (eg in A controller)
appDelegate.sharedString = string;
//to get (eg in B controller)
NSString* string = appDelegate.sharedString;
作为属性的替代方法,您可以在头文件中使用静态变量:
static NSString* staticString;
#imports
头文件的任何对象都可以访问它。虽然不是真正的 Objective-C 方式。
对于更复杂的情况,您可能需要创建一个单例对象来访问您的模型数据。
2/尝试:
[self performSegueWithIdentifier: @"secondViewSegue" sender:self];
确保 Segue 是从您的 viewController 连接的,而不是 Navigation Controller。
关于ios - 在两个不同的 Storyboard之间传递数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15465046/