Reputation: 5936
As the title suggestes im trying to work out how I can show an alert after a button recives a certain amount of taps. So far ive come up with
- (IBAction)count:(id)sender {
{
UITouch *touch = [count];
if (touch.tapCount == 4)
{
}
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title" message:@"My alert text here" delegate:nil cancelButtonTitle: @"Ok" otherButtonTitles: nil];
[alert show];
}
}
The above isnt working, Ive set up my button count
as action and as an outlet counted
Upvotes: 0
Views: 111
Reputation: 4140
Define somewhere on the begining of code static value:
static int numberTouches;
And set somewhere (in viewWillAppear):
numberTouches = 0;
Than:
- (IBAction)count:(id)sender {
{
numberTouches++;
if(numberTouches == 4)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title" message:@"My alert text here" delegate:nil cancelButtonTitle: @"Ok" otherButtonTitles: nil];
[alert show];
}
}
Remeber to set 0 to your numberTouches in place where you want to do this, for example in viewDidDissapear, or if user taped somewhere else.
Upvotes: 0
Reputation: 19030
That code doesn't make a lot of sense (I'm surprised it compiles, does it?). UITouch isn't part of when you select a button. I think what you need to do is to keep a count of how many times the button is pressed, and store it as an instance variable.
For example (in your implementation):
@interface ClassName() {
NSUInteger m_buttonTouchCount;
}
@end
// Set m_buttonTouchCount to 0 in your init/appear method, whenever it's appropriate to reset it
- (IBAction)count:(id)sender {
{
m_touchButtonCount++
if (m_touchButtonCount == 4)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title"
message:@"My alert text here"
delegate:nil
cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[alert show];
m_touchButtonCount = 0; // Not sure if you want to reset to 0 here.
}
}
Upvotes: 2