Question

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;
        }else{
            i = arc4random() % [self.collectionOfData count];
        }

            DeatilViewController *dest = [segue destinationViewController];
            dest.data = [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?

Was it helpful?

Solution 2

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

OTHER TIPS

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.)

-(void)viewDidAppear:(BOOL)animated
{
    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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top