Hide button on one touch itself

≯℡__Kan透↙ 提交于 2019-12-24 01:57:06

问题


i want to hide button on one touch itself. when the user touches the button that button should get hide but on one touch.The buttons are moving randomly. The moving buttons shoul get hide on touch. i have done it but after two three times pressing only it gets hide. i am using touchupinside event. Can anyone help me?

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

Thanks in advance


回答1:


Replace your code with this Button touchUpInside

-(IBAction)hide:(id)sender
{
    UIButton *tmp = (UIButton *)sender;
    tmp.hidden = YES;
}



回答2:


Replace your first IBAction method with this one:

 -(IBAction)clickButton1:(id)sender
{
  UIButton *button1 = (UIButton *)sender;
  if (button1.tag==1)
 {
   button1.hidden=TRUE;
 }
 else
 {
   button1.hidden=FALSE;
 }
}



回答3:


You can create your button on viewDidLoad with loop

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

after that you can control the show hide with following code.

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


来源:https://stackoverflow.com/questions/10101253/hide-button-on-one-touch-itself

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!