Swipe gesture to next view controller crashes

淺唱寂寞╮ 提交于 2019-12-12 05:48:14

问题


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:


Create UIviewController obj like this

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



来源:https://stackoverflow.com/questions/42183635/swipe-gesture-to-next-view-controller-crashes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!