2

ワンタッチ自体でボタンを非表示にしたい。ユーザーがボタンに触れると、そのボタンは非表示になりますが、1 回のタッチでボタンがランダムに移動します。動くボタンはタッチすると非表示になります。私はそれをしましたが、2回3回押すだけで非表示になります。touchupinside イベントを使用しています。誰でも私を助けることができますか?

-(IBAction)clickButton1:(id)sender
{
    if (button1.tag==1)
    {
        button1.hidden=TRUE;
    }
    else
    {
        button1.hidden=FALSE;
    }
}
-(IBAction)clickButton2:(id)sender
{
    if(button1.hidden==TRUE && button3.hidden==FALSE) 
    {
        button2.hidden=TRUE;
    }
    else
    {
        button2.hidden=FALSE;
    }
}

前もって感謝します

4

3 に答える 3

3

コードをこの Button touchUpInside に置き換えます

-(IBAction)hide:(id)sender
{
    UIButton *tmp = (UIButton *)sender;
    tmp.hidden = YES;
}
于 2012-04-11T06:59:26.017 に答える
0

最初の IBAction メソッドを次のメソッドに置き換えます。

 -(IBAction)clickButton1:(id)sender
{
  UIButton *button1 = (UIButton *)sender;
  if (button1.tag==1)
 {
   button1.hidden=TRUE;
 }
 else
 {
   button1.hidden=FALSE;
 }
}
于 2012-04-11T07:00:48.447 に答える
0

ループを使用してviewDidLoadにボタンを作成できます

-(void) viewDidLoad{
     for ( c = 0; c < 10; c++ ){
           Buttons[c] = [[UIButton alloc] init];
           Buttons[c].tag = c;
      }
}

その後、次のコードで表示非表示を制御できます。

-(IBAction)yourActionMethod:(id)sender
{
    //your normal action codes here
    UIButton *tmp = (UIButton *)sender;
    if (tmp.tag == 0) {
          // some codes
    } else {....}

    //control buttons of the 

    for (int i = 0; i < tmp.tag; i++){
          Buttons[i].hidden = yes;
    }
    
}
于 2012-04-11T07:31:38.150 に答える