Question

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

Était-ce utile?

La solution 4

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.

Autres conseils

try this code:

you add parent class

[[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(actionremovecalender:)
                                                 name:@"subMitReport"
                                               object:nil];
-(void)actionremovecalender:(NSNotification *)notification
{
    [self ViewDidLoad]
}

call child class

[[NSNotificationCenter defaultCenter]postNotificationName:@"subMitReport" object:nil]

You can send a NSNotification that the parent will receive, or you can set a delegate with a method implemented by the parent view.

In both cases, just reload the view.

In a one-to-one relation, you should prefer the delegation pattern. Just add a weak reference of viewcontrollerA to your viewcontrollerB. You can just call a method (in this case viewDidLoad method) of viewcontrollerA using the reference so you can refresh the views. But I'd prefer declaring a protocol for delegation to prevent tight coupling of two view controllers.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top