布尔变量的值不变,不会在情节提要中将dismissViewControllerAnimated从子级更改为父级 [英] Boolean Variable's value not change dismissViewControllerAnimated From Child to Parent in Storyboard
问题描述
我不是初学者,但我无法弄清楚这个愚蠢的问题.我有两个视图控制器,例如 Parent 和 Child 是类. 父级是基类,子级是子类,但是除了这些布尔值,我无法继承任何数据.
I am not a beginner but I can't figure out this silly issue. I have Two View Controllers For Example Parent and Child are classes. Parent is a base class and child is a sub class But I can't Inherited any data except these bool.
在父类中,我使用一个BOOL
变量,该变量在 Parent.h
In Parent Class I use one BOOL
Variable which I declare in Parent.h
@property (nonatomic, assign) BOOL isChange;
此后,我合成此变量并在viewDidLoad
After that I synthesis this variable and initialize default False in viewDidLoad
isChange = FALSE;
现在,我在 Child 类中使用此变量,并将其值更改为True
Now, I use this variable in Child Class and I Change the value to True
Parent.isChange = TRUE;
在进行此更改之前,我还在 Child 类中的alloc
和init
Parent 类.
Before this change I also alloc
and init
Parent Class in Child class.
Parent = [[Parent alloc] init];
但是问题是当我解雇该班级并转到父级班级isChange
值不变时.
But the issue is when I Dismiss this Class and go to Parent Class isChange
value not change.
[self dismissViewControllerAnimated:YES completion:nil];
我签入了父母班级
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
if (isChange == TRUE) { // Here isChange Return NO.
[self refresh:nil];
}
}
我无法弄清楚我的错误.
I can't figure out my mistake.
推荐答案
您无法获得TRUE
值,因为在子类中,您的alloc
init
.它创建一个新的Instance
.最好全局声明此布尔变量.我会给你例子.
You can't get TRUE
value because in child class your alloc
init
. It create a new Instance
. It's better to declare this Boolean variable Globally. I will give you the Example.
在Common.h
@property (nonatomic) BOOL isChange;
在Common.m
- (void)checkIsAnyChange:(BOOL)isChange {
_isChange = isChange;
[self updateChangeCount:UIDocumentChangeDone];
}
现在在父级和子级中与此Boolean
一起使用以进行检查.
And now use with this Boolean
in Parent and Child Class for Check.
这篇关于布尔变量的值不变,不会在情节提要中将dismissViewControllerAnimated从子级更改为父级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!