How to enable only one button and make user interaction No

In my project in one view, I want to make the whole view disabled except for one button , so I use

[self.view setUserInteractionEnabled:NO]; 

Since I have many components, it is difficult to enable and disable each component, so I use it.

But I want to enable one button, there are many buttons.

+4
source share
4 answers

According to XLC you can do as

 for (UIView *view in [self.view subviews]) { if (view.tag==101)// set your button tag that you don't wont disable [ view setUserInteractionEnabled:YES]; else [ view setUserInteractionEnabled:NO]; } 
+3
source

Try the following:

 for (UIView *viewButton in [self.view subviews]) { if ([viewButton isKindOfClass:[UIButton class]]) //In case you want check only for the buttons. { if (viewButton.tag==1)//Make sure that you have already set the tag=1 for the button,which you don't want to disable { [viewButton setUserInteractionEnabled:YES]; } else { [viewButton setUserInteractionEnabled:NO]; } } } 
+1
source

try this, hope this helps you

  for (id subview in [self.view subviews]) 
 {
    if ([subview isKindOfClass: [UIButton class]] && [subview tag] == 1)
    {
          [subview setUserInteractionEnabled: YES];
    }
    else
    {
          [subview setUserInteractionEnabled: NO];
    }
 } 
+1
source

If you use [self.view setUserInteractionEnabled:NO]; Then all your browsing is turned off, including subviews. Therefore, it is best to loop through all the subitems and disable and enable as required.

0
source

Source: https://habr.com/ru/post/1501978/


All Articles