-1

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.

Mihir Oza
  • 2,768
  • 3
  • 35
  • 61
  • I normally downvote users who ask for urgency here, especially experienced ones - but the question is otherwise very good so I will refrain on this occasion. Note that as soon as you submit a problem to a volunteer site on the internet, it does not become urgent for anyone else, and it will not be treated with any greater priority than any of the other questions that came in today. – halfer Mar 09 '16 at 09:00
  • Do you have Answer for this Question? – Mihir Oza Mar 09 '16 at 13:45
  • I am a bit confused. Is the `Child` inheriting from `Parent` or are they just two random class names (i.e. can you show more of your `.h` file? In the `Child` instance where are you setting `Parent.isChanged = TRUE`? – Firo Mar 09 '16 at 14:03
  • Actually I use this Boolean in child class to check Is any Webservice call or not. – Mihir Oza Mar 09 '16 at 14:13
  • Is it possible without 'prepareForSegue' ? – Mihir Oza Mar 09 '16 at 14:14
  • I see what you are trying to do, but I feel to much of the context is missing. It may help to add some additional code, like how you are presenting the VC's. – Firo Mar 09 '16 at 14:43
  • I already specify most of the things like I use Storyboard, I also specify Parent Class Declaration. What you need Please tell me I will Add in My Question. – Mihir Oza Mar 09 '16 at 16:06

2 Answers2

2

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.

0

[[Parent alloc] init] creates a new instance of Parent. If you change the value of some property in that instance, there's no reason to expect that the value will also change in some other instance of Parent.

If you want to verify what's going on, print the address of the parent when you make the assignment and the value of self where you test isChange. If they are not the same, then you're dealing with separate objects.

Phillip Mills
  • 30,888
  • 4
  • 42
  • 57
  • is it possible without prepareForSegue method ? – Mihir Oza Mar 09 '16 at 14:22
  • I don't understand your comment. What does your original question have to do with segues? – Phillip Mills Mar 09 '16 at 14:23
  • I checked your answer http://stackoverflow.com/a/14568595/3378413 Here, I think you use prepareForSegue for data passing. – Mihir Oza Mar 09 '16 at 14:26
  • Did you understood My Question or not? Please see my comment in Question for what I want. – Mihir Oza Mar 09 '16 at 14:31
  • I understand that you're changing one `Parent` object and expecting the change to affect a different `Parent` object. (Otherwise, no, I have no idea why you're talking about "Inherited" data, for example.) – Phillip Mills Mar 09 '16 at 14:38