Question

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

Was it helpful?

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.

OTHER TIPS

I updated your view controller and now it is working for all gestures you want. Please check out and let me know.

- (void)viewDidLoad{
[super viewDidLoad];
//gesture for tap
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(click)];
[self.view addGestureRecognizer:tap];

//gesture for right swipe
UISwipeGestureRecognizer *rightRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(rightSwipeHandle:)];
rightRecognizer.direction = UISwipeGestureRecognizerDirectionRight;
[rightRecognizer setNumberOfTouchesRequired:1];
[self.view addGestureRecognizer:rightRecognizer];
[rightRecognizer release]; 

//gesture for right swipe
UISwipeGestureRecognizer *leftRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(leftSwipeHandle:)];
leftRecognizer.direction = UISwipeGestureRecognizerDirectionLeft;
[leftRecognizer setNumberOfTouchesRequired:1];
[self.view addGestureRecognizer:leftRecognizer];
[leftRecognizer release];}


- (void)rightSwipeHandle:(UISwipeGestureRecognizer*)gestureRecognizer{ [_text setText:@" World"]; }

- (void)leftSwipeHandle:(UISwipeGestureRecognizer*)gestureRecognizer{ [_text setText:@"World"]; }

- (void)click{ [_text setText:@"Hello World"]; }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top