I'm trying to create a view in an app with a button that if tapped 3 times something happens. I have looked at multiple questions and used multiple codes but I just cannot get it to work. This is my code:
#import "ViewController3.h"
#import <AVFoundation/AVFoundation.h>
#import "ViewController.h"
@interface ViewController3 ()
{
AVAudioPlayer *_player;
}
@end
@implementation ViewController3
- (void)viewDidLoad {
[super viewDidLoad];
NSString *path = [NSString stringWithFormat:@"%@/sound.m4a", [[NSBundle mainBundle] resourcePath]];
NSURL *soundUrl = [NSURL fileURLWithPath:path];
_alarmPlayer.numberOfLoops = -1;
_alarmPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:soundUrl error:nil];
[ _player play];
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture:)];
UIEvent *event;
UITouch *touch = [[event allTouches] allObjects]; //warning
tapGesture.numberOfTapsRequired = 3;
[self.view addGestureRecognizer:tapGesture];
}
- (void)handleTapGesture:(UITapGestureRecognizer *)sender {
if (sender.state == UIGestureRecognizerStateRecognized) {
// handling code
}
}
- (IBAction)iconsBtn:(id)sender {
if(touch.tapGesture) = 3) { //errors 1 and 2
[ _alarmPlayer stop];
}
else
NSLog(@"UGHHHHH");
}
Warning:
- Incompatible pointer types initializing 'UITouch *' with an expression of type 'NSArray *'
Errors:
- Use of undeclared identifier 'touch'
- Expected expression
How do I get rid of those errors and get this to function correctly?
Thanks!
Also if anyone wants to mark me down please will you comment to explain why so I can learn from it.