Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
215 views
in Technique[技术] by (71.8m points)

objective c - Boolean Variable's value not change dismissViewControllerAnimated From Child to Parent in Storyboard

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.

In Parent Class I use one BOOL Variable which I declare in Parent.h

@property (nonatomic, assign) BOOL isChange;  

After that I synthesis this variable and initialize default False in viewDidLoad

isChange = FALSE;  

Now, I use this variable in Child Class and I Change the value to True

Parent.isChange = TRUE;  

Before this change I also alloc and init Parent Class in Child class.

Parent = [[Parent alloc] init];  

But the issue is when I Dismiss this Class and go to Parent Class isChange value not change.

[self dismissViewControllerAnimated:YES completion:nil];  

I checked in Parent Class

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    if (isChange == TRUE) {  // Here isChange Return NO.
        [self refresh:nil];
    }
}

I can't figure out my mistake.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

Declare your variable in Common.h

@property (nonatomic) BOOL isChange;  

Define in Common.m

- (void)checkIsAnyChange:(BOOL)isChange {
    _isChange = isChange;
    [self updateChangeCount:UIDocumentChangeDone];
}  

And now use with this Boolean in Parent and Child Class for Check.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...