Search code examples
ioscore-datapage-curl

how to refresh the viewdidload for parent viewcontroller


I have 2 viewcontrollers with segue "page curl"

viewcontrollerA => pagecurl => viewcontrollerB and Now I want to update viewcontrollerA since user make some change at viewcontrollerB.

I tryed:

UIStoryboard*  sb = [UIStoryboard storyboardWithName:@"mystoryboard"
                                          bundle:nil];
UIViewController* vc = [sb instantiateViewControllerWithIdentifier:@"ExampleViewController"];
[vc ViewDidLoad]; // or ViewWillAppear or ViewDidApear

it works only for the NSLog I put in those functions. but none of them works with the function which check out Coredata and update the interface. please help


Solution

  • ViewWillApear or ViewDidApear will be called since there is any object changes in the viewcontroller, but if you want to change your viewcontrollerA from another viewcontrollerB, that require NSNotificationCenter to call the function from viewcontrollerA

    you can always use NSNotificationCenter to update your parent viewcontroller

    At your parent viewcontroller put this:

    //since child view controller calls turnItOff, notification center calls function "turnButtonCountinuesOff"
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(turnButtonCountinuesOff) name:@"turnItOff" object:nil];
    

    turnButtonCountinuesOff is your function at parent viewcontroller

    At your child viewcontroller put this:

    //connect to parent UI view controller calls notification turnItOff.
    [[NSNotificationCenter defaultCenter] postNotificationName:@"turnItOff" object:nil];
    

    hope it helps.