我知道共享数据的一种方法是继续。但在我的应用程序中,我有多个包含VC数量的选项卡。例如userName
和address
。我想向一些风险投资家展示这些信息。我每次查询云时都是不正确的。我在回答第一部分:answer。但作为新手,我不确定如何定义MyDataModel
。它是一个NSObject类吗?我很感激任何人都可以将这个类定义为两个NSString
字段的例子。以及如何在VC和AppDelegate中访问这些字段。如何在多个ViewControllers之间共享数据?
里面的AppDelegate
@interface MyAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate>
{
MyDataModel *model;
AViewController *aViewController;
BViewController *bViewController;
...
}
@property (retain) IBOutlet AViewController *aViewController;
@property (retain) IBOutlet BViewController *aViewController;
@end
@implementation MyAppDelegate
...
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
...
aViewController.model = model;
bViewController.model = model;
[window addSubview:tabBarController.view];
[window makeKeyAndVisible];
}
内VC:
@interface AViewController : UIViewController {
MyDataModel *model;
}
@property (nonatomic, retain) MyDataModel *model;
@end
@interface BViewController : UIViewController {
MyDataModel *model;
}
@property (nonatomic, retain) MyDataModel *model;
@end
我唯一需要的是在哪里定义MyDataMode
以及如何访问它的字段?
创建一个NSObject的子类,并在.h文件中创建'@property(nonatomic,retain)NSString * str1;' '@property(nonatomic,retain)NSString * str2;' –