JackyJohnson
JackyJohnson

Reputation: 3126

EXC_BAD_ACCESS when retrieving views from transition context on iPhone 4

I have the following code, which works perfectly on my iPhone 5 and all the iPhone simulators, but it crashes on my iPhone 4. I get EXC_BAD_ACCESS on the last line where I pass UITransitionContextToViewKey to my transition context.

I have a clean analyze and build, and the same happens for both UITransitionContextFromViewKey and UITransitionContextToViewKey.

My iPhone 4 is on iOS 7.1.2, my deployment target is 7.0, targeted build base SDK 8.0.

Anyone knows what to do here? thx.

- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext
{
    // get transition parameters from context
    UIView *containerView = transitionContext.containerView;
    UIViewController *destinationViewController =
    [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];

    if ([destinationViewController.title isEqualToString:@"ListController"]) {

        // get source and destination views
        UIView *sourceViewSnapshot = [self.view snapshotViewAfterScreenUpdates:YES];

        UIView *destinationView = [transitionContext viewForKey:UITransitionContextToViewKey]; // EXC_BAD_ACCESS

// ...
}

Upvotes: 2

Views: 700

Answers (2)

Mike Dickman
Mike Dickman

Reputation: 81

The viewForKey method is iOS 8 and up, but the viewControllerForKey method is supported in iOS 7. A small change to your code gets the view in iOS 7:

   UIView *destinationView = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey].view;

Upvotes: 6

Olotiar
Olotiar

Reputation: 3274

From the documentation:

UITransitionContextToViewKey

Available in iOS 8.0 and later.

You can't run that code on iOS 7

You might want to add runtime system version checks and branch out to a iOS 7 compatible code at this point if you want to maintain compatibility with this version of the system

Upvotes: 1

Related Questions