0

タイトルが示唆するように、ボタンが一定量のタップを受け取った後にアラートを表示する方法を見つけようとしています。これまでのところ、思いついた

- (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

4

2 に答える 2

2

そのコードはあまり意味がありません (コンパイルできることに驚いていますよね?)。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.
    }
 }
于 2012-10-27T22:07:42.880 に答える
0

コードの先頭のどこかに静的値を定義します。

static int numberTouches;

そしてどこかに設定します(viewWillAppearで):

numberTouches = 0;

よりも:

- (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];
    }
} 

たとえば、viewDidDissapear で、またはユーザーが別の場所で録音した場合など、これを実行したい場所で numberTouches に 0 を設定することを忘れないでください。

于 2012-10-27T22:08:04.930 に答える