Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable button in UIActionSheet?

Tags:

iphone

I need to disable the buttons in UIActionSheet. after some operations i need to enable them again. So is there a way to do this.

Thanks

like image 986
satish Avatar asked Jul 22 '09 05:07

satish


1 Answers

Based on a number of thread, i've aggregated an answer into a category on UIActionSheet, adding a setButton:toState method as follows. Hope it helps:

@interface UIActionSheet(ButtonState)
- (void)setButton:(NSInteger)buttonIndex toState:(BOOL)enbaled;
@end

@implementation UIActionSheet(ButtonState)
- (void)setButton:(NSInteger)buttonIndex toState:(BOOL)enabled {
    for (UIView* view in self.subviews)
    {
        if ([view isKindOfClass:[UIButton class]])
        {
            if (buttonIndex == 0) {
                if ([view respondsToSelector:@selector(setEnabled:)])
                {
                    UIButton* button = (UIButton*)view;
                    button.enabled = enabled;
                }
            }
            buttonIndex--;
        }
    }
}
@end
like image 180
Reuven Avatar answered Sep 19 '22 00:09

Reuven