0
votes

I have two view controllers. I created a custom segue from the first viewcontroller to the second one and viceversa and linked both segues to the following class: (I downloaded the class from an internet tutorial)

#import "SlideLeftCustomSegue.h"

@implementation SlideLeftCustomSegue

- (void)perform{
    UIViewController *srcViewController = (UIViewController *) self.sourceViewController;
    UIViewController *destViewController = (UIViewController *) self.destinationViewController;

    CATransition *transition = [CATransition animation];
    transition.duration = 0.3;
    transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    transition.type = kCATransitionPush;
    transition.subtype = kCATransitionFromRight;
    [srcViewController.view.window.layer addAnimation:transition forKey:nil];

    [srcViewController presentViewController:destViewController animated:NO completion:nil];
}

@end

(I just changed the transition from "Right" lo "Left" depending on which viewcontroller I am) I call the segue from a swipe gesture.

It works as expected, but sometimes, randomly, when I swipe to call the segue, it crashes. This is the error that appears.

pru(745,0x1ae6d5c40) malloc: *** error for object 0x170014930:      Invalid pointer dequeued from free list
*** set a breakpoint in malloc_error_break to debug
(lldb) 

How can I fix this?

1
Run an NSLog in your swipe method and check if you fire it off twice which usually can happen. You should include the swipe method code in your question. If this is the problem, You should create a BOOL property, and before firing the swipe animation you set the bool isAnimating = YES; and check that you only fire the animation when isAnimation == NO. If this solves your issue let me know I will add the answer so you can accept it here.user5890979
Thank you for your answer. I did what you said but it didn't work. Any other ideas? I appreciate your time, thank you! @Sneakuser1935016
I would need a little more details than "didn't work" to help you further. Did you test and made sure 100% if the swipe gets called once and once only? And you still got the crash when called only once?user5890979
Thank you @Sneak.. I already fixed it. I was setting the "touches" method to 2, instead of setting the "touchesrequired".user1935016
I'm glad you got it to work. I thought it had to do with your gesture. good job.user5890979

1 Answers

-1
votes

Create UIviewController obj like this

SomeViewController *someViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"SomeViewController"];