presentViewController completion block not executing

1.8k Views Asked by At

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.

2

There are 2 best solutions below

4
On

If on any of my viewcontrollers there is a property named exactly currentAction, the completion blocks won't execute in the whole application ! Can someone please confirm ?

That's probably because UIViewController has an instance variable called _currentAction, as you can see in this part of UIViewController.h:

id               _dimmingView;
id               _dropShadowView;

id                _currentAction;
UIStoryboard     *_storyboard;

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:

@synthesize currentAction=_myCurrentAction;

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.

6
On

Don't use alloc/init to create a view controller. Ether load it from a storyboard using instantiateViewControllerWithIdentifier:, or load it from a nib using initWithNibName:bundle:.

That is likely the cause of your problem.