質問

I have a modal view controller presented and just before I dismiss it, I need to call a delegate method which tells the parent view controller to update. (As methods like viewWillAppear are not called when dismissing a modal view controller).

So my code looks like this:

[delegate addEquipmentDidSave:YES];
[self dismissViewControllerAnimated:YES completion:nil];

Very simple. Send a message back, saying, update now! And then just dismiss the view. However, while both of these lines are called, the delegate method never runs. So I check that the delegate it set correctly. When I present the modal view I set the delegate, so its all connected.

Its as if the delegate method isn't getting a chance to run before the view is dismissed. Is this possible? What do you think might be the issue?

Thanks.

役に立ちましたか?

解決

Before calling your delegate method first check whether it's available or not

if ([self.delegate respondsToSelector:@selector(addEquipmentDidSave:)] )
{
    NSLog("Yes it's available");
    [self.delegate addEquipmentDidSave:YES];
}

[self dismissViewControllerAnimated:YES completion:nil];

他のヒント

Do you see that last parameter, the one called completion? That block is called after the view controller is dismissed. Do what you want to do in there.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top