I have a strange problem, the completion block from presentViewController
doesn't execute lately.
This is the code called on button tap
DebugViewController * x = [[DebugViewController alloc] init];
x.view.backgroundColor = [UIColor redColor];
[self presentViewController:x animated:YES completion:^{
NSLog(@"Hello world %@" , self );
}];
DebugViewController
is this class, self
is a UIViewController
in a structure like this:
JASidepanels
---> (center panel) UINavigationController
---> self
As expected, the exact same code works in any other project, but it isn't working in mine since a few weeks. I recently added JASidePanels
and some other Pods.
Here is what know surely :
- the modal is presented, viewWillAppear and viewDidAppear are called, it animates in, it works correctly
- viewWillDisappear is called on presenting VC, dealloc isn't, so it is live.
- Other blocks work.
- It is on the main thread
Any idea how could I debug why the block doesn't execute for me ?
Edit: Wow, this is extremely strange. I debugged whole day and tried to delete code line-by-line. However it seems I found something really really interesting. If on any of my viewcontrollers there is a property named exactly currentAction
(which is the case in one of my VCs), the completion blocks won't execute in the whole application ! Can someone please confirm ? Here is a gist GIST, change it to currentAction
.
That's probably because
UIViewController
has an instance variable called_currentAction
, as you can see in this part of UIViewController.h:Declaring a property called
currentAction
and using the default synthesis for the accessors would interfere with that ivar. To avoid that, explicitly synthesize the accessors and provide a different name for the ivar to back your property. Try adding a line like this to your class:That might help you avoid interfering with the existing ivar, as long as UIViewController only accesses
_currentAction
directly and doesn't use any internally-declared accessor or KVC.