正如标题所暗示的,我正在尝试找出如何在按钮获得一定数量的点击后显示警报。到目前为止,我想出了
- (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];
}
}
上面的方法不起作用,我已经将按钮
count
设置为动作,并将其设置为插座counted
最佳答案
该代码没有多大意义(我很惊讶它可以编译,对吗?)。选择按钮时,UITouch不在其中。我认为您需要做的是保持对按钮被按下的次数的计数,并将其存储为实例变量。
例如(在您的实现中):
@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.
}
}
关于objective-c - 如何在收到点击次数后显示警报 View ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13104535/