dismissViewControllerAnimated completion method not working
ios, objective-c
Solution
I think this what you are looking for,
[self dismissViewControllerAnimated:YES completion:^{
[self.mainController aMethod];
}];
In the above code you need to declare `self` outside the block and use it as,
__block SecondViewController *object = self;
[self dismissViewControllerAnimated:YES completion:^{
[object.mainController aMethod];
}];
Just to avoid `self` getting retained in block.
Update:
Got the issue now. You need to declare `mainController` as a property in your .h file of `secondViewController`. After that when you are presenting the `secondViewController` from `maincontroller`, you need to set it as,
secondViewController.maincontroller = self;
[self presentViewController:secondViewController animated:YES completion:Nil];
In your `SecondViewController.h` file,
@property(nonatomic, assign) MainController *mainController;
In your `SecondViewController.m` file,
@synthesis mainController;
Update 2:
If you do not want to declare `maincontroller` as a property, try this. I am not sure whether this is the right way to do. But it looks like it used to work.
MainController *mainController = (MainController *)[self.view.superview nextResponder];
[self dismissViewControllerAnimated:YES completion:^{
[mainController aMethod];
}];
Update 3(Suggested):
This should work for you. Check it.
MainController *mainController = (MainController *)self.parentViewController;
[self dismissViewControllerAnimated:YES completion:^{
[mainController aMethod];
}];
Problem
Here's my app design. I have `mainController` which presents `secondViewController`. Now, I want to dismiss `secondViewController` and subsequently call the method `aMethod` on `mainController` like so: ``` [self dismissViewControllerAnimated:YES completion:aMethod]; ``` But this gives me the error `use of undeclared identifier 'aMethod'` Obviously I am not using the completion handler correctly, but I cannot figure out the correct way.