[英]How to pass Data to a ViewController without presenting it?
i want to pass from a view controller 4 BOOL Values to my ChooseLevelVC: 我想从一个视图控制器4 BOOL值传递给我的ChooseLevelVC:
if (_moves >=4) {
clvc.level1Completed3 = 1;
}
if (_moves == 3) {
clvc.level1Completed2 = 1;
}
if (_moves == 2) {
clvc.level1Completed1 = 1;
} else
clvc.level1Completed = 1;
But i don't want to present ChooseLevelVC. 但我不想介绍ChooseLevelVC。 It should work in Background.
它应该在后台工作。 This Bool Values changes the Image of Buttons in ChooseLevelVC.
此布尔值更改ChooseLevelVC中按钮的图像。
My Code works fine if i present ChooseLevelVC with: 如果我通过以下方式提供ChooseLevelVC,则我的代码工作正常:
ChooseLevelViewController *clvc = [self.storyboard instantiateViewControllerWithIdentifier:@"chooseLevelViewController"];
if (_moves >=4) {
clvc.level1Completed3 = 1;
}
if (_moves == 3) {
clvc.level1Completed2 = 1;
}
if (_moves == 2) {
clvc.level1Completed1 = 1;
} else
clvc.level1Completed = 1;
[self presentViewController:clvc animated:NO completion:^(){
}];
if i don't present ChooseLevelVC, nothing happens. 如果我不显示ChooseLevelVC,则什么也不会发生。 Do i have to save the Values?
我必须保存值吗? When yes, how?
是的时候如何?
thanks! 谢谢!
You'll need to store your ChooseLevelViewController
in a local property: 您需要将
ChooseLevelViewController
存储在本地属性中:
@property (nonatomic, strong) ChooseLevelViewController *chooseLevelViewController;
... so that you can instantiate it once in viewDidLoad
: ...以便您可以在
viewDidLoad
实例化一次 :
- (void)viewDidLoad{
[super viewDidLoad];
// This is the only place you need to instantiate this view controller!
self.chooseLevelViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"chooseLevelViewController"];
}
... and then configure it as needed: ...,然后根据需要进行配置:
self.chooseLevelViewController.level1Completed1 = 1;
... eventually presenting it whenever you like: ...最终在您愿意时展示:
[self presentViewController: self.chooseLevelViewController animated:NO];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.