Search code examples
iphoneobjective-cswipeuiswipegesturerecognizer

Three gestures crash my iPhone


I have problem with swipe with three gestures

in my .m :

- (IBAction)click:(id)sender {

    [_text setText:@"Hello World"];
}

- (IBAction)resetText:(id)sender {

    [_text setText:@"Reset"];
}

when I clicked on the screen the output message "Hello World" will be shown on label and it should shown "Reset" when I swipe three fingers from up to down, but it crashes

the weird thing is when I change the name of IBAction from "resetText" to for example "reset" or whatever name without capital letter it works. With any capital letter, it crashes

this is the Xcode file


Solution

  • I looked at your example project, and it seems that:

    • The crash only occurs on actual devices
    • The crash only occurs when the swipe gesture requires 3 or more touches

    This looks to me like a bug in the UIGestureRecognizer class when added using Interface Builder, so there isn't much you can do about it now. I filed a radar (#14399827) with Apple describing this issue. You should probably do this as well.


    However, you can work around this bug by creating the gesture recogniser in code instead of in the storyboard as you are now.

    Remove the gesture recogniser from your storyboard (delete it completely), then add this to the viewDidLoad method in your view controller:

    - (void)viewDidLoad
    {
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
    
        UISwipeGestureRecognizer *recogniser = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(resetText:)];
        [recogniser setDirection:UISwipeGestureRecognizerDirectionDown];
        [recogniser setNumberOfTouchesRequired:3];
        [self.view addGestureRecognizer:recogniser];
    }
    

    I understand that this isn't ideal, as it may be more convenient in some cases to add the view controller directly to the storyboard, but unfortunately it seems that you can't currently do that due a bug in Apple's implementation.