5

In my project in one view i want to make all the view disable except one button, So i am using

[self.view setUserInteractionEnabled:NO];

As i have many components it is difficult to enable and disable every component so i am using it.

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

iJade
  • 23,144
  • 56
  • 154
  • 243
kiri
  • 1,977
  • 5
  • 27
  • 55

4 Answers4

3

As per XLC You can do like

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];
    }
Toseef Khilji
  • 17,192
  • 12
  • 80
  • 121
1

Try this:

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];
    }
   }
}
Master Stroke
  • 5,108
  • 2
  • 26
  • 57
1

try this one 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];
   }
}
MobileDev
  • 1,024
  • 9
  • 21
0

If you use [self.view setUserInteractionEnabled:NO]; Then your entire view getting disable including subviews. So better to loop all subviews and disable and enable according to requirement.

kumar123
  • 791
  • 7
  • 21