Search code examples
objective-cuiviewcontrollerios9boolean-expressionviewdidappear

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.


Solution

  • 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.