Shake gesture and prepare for seuge - Unbalanced calls to begin/end appearance transitions

I have an UITabelViewController (mainViewCtrl), if the user select a cell, a new UIViewController (detailViewCtrl) is been pushed into the "Scene", with some detail data regarding the selected cell. - pretty simple stuff.

If the user Shakes the phone, (detailViewCtrl) will been showed with some random detail data.

Here is my prepareForSeque code:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender

    if ([segue.identifier isEqualToString:@"DetailViewSeque"])
        int i;

        if ([sender isKindOfClass:[UITableViewCell class]]){
            UITableViewCell *cell = (UITableViewCell*)sender;
            NSIndexPath *indexPath = [self.minifigsTableView indexPathForCell:cell];
            i = indexPath.row;
            i = arc4random() % [self.collectionOfData count];

            DeatilViewController *dest = [segue destinationViewController];
   = [self.collectionOfData objectAtIndex:i];



The Code is pretty simple, nothing fancy. My problem is, if the user shakes the Phone while the transitions between the two ViewController (mainViewCtrl and detailViewCtrl) is going on, I will get this error:

Unbalanced calls to begin/end appearance transitions for.

I understand why this causes a problem.

But how do I solve it? How do I somehow stop the UIGestureEvent from been fired, while the transitions is active?


May be you can add a boolean property "isInTransit".

Set it to false in your viewWillAppear,

set it to true in your prepareForSegue (just up to your int i;).

And in your motionEnded (shake method) test if (isInTransit=true) -> don't handle the shake, so don't fire the segue.

Hop this will help

This is how I solved my problem.

First I added: @property BOOL isInTransit;

Then I added the viewDidAppear method to my code, and set isIntransit to true (viewDidAppear will be called after the transitions has ended.)

    self.isInTransit = true;

Finally I added an if statement to my motionBegan method, and set isInTransit to false just before preformeSegueWithIdentifier is called:

 - (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event
        if (event.subtype == UIEventSubtypeMotionShake)
            if (self.isInTransit){
                self.isInTransit = false;
                [self performSegueWithIdentifier:@"DetailViewSeque" sender:self];

Thanks to Armand DOM for helping me out.

Need Your Help

Is it possible to change HANDLE that has been opened for synchronous I/O to be opened for asynchronous I/O during its lifetime?

winapi asynchronous synchronous createfile overlapped-io

Most of my daily programming work in Windows is nowadays around I/O operations of all kind (pipes, consoles, files, sockets, ...). I am well aware of different methods of reading and writing from/to