Qasem
Qasem

Reputation: 67

iOS - Can not set Button 'Disable', without removing the content of it

Sorry for what should be a simple solution.

I am trying to 'Disable' a button in code using the following Code:

in the first Class which Called 'CheckBox':

checkBox.h :

@interface CheckBox : UIViewController 
{   
   BOOL checkboxSelected;
   UIButton *checkBoxButton;
}

 @property (nonatomic, retain) IBOutlet UIButton *checkBoxButton;


- (IBAction)checkBoxButton:(id)sender;


-(void) setCheckBoxSelected:(BOOL)checkingStatus;
-(void) setCheckBoxEnabled:(BOOL)enablingStatus;

in checkBox.m :

- (IBAction)checkBoxButton:(id)sender {

if (checkboxSelected == 0){
    [checkBoxButton setSelected:YES];
    checkboxSelected = 1;

} else {

    [checkBoxButton setSelected:NO];
    checkboxSelected = 0;
      }
}

 -(void) setCheckBoxSelected:(BOOL)checkingStatus {

   checkBoxButton.selected = checkingStatus;
     }

 -(void) setCheckBoxEnabled:(BOOL)enablingStatus {

    [checkBoxButton setEnabled:enablingStatus];
   }

and in the implementation of another class which called 'MainViewController.m' :

- (void)viewDidLoad{

     allTransactionCheckBox = [[CheckBox alloc] init];
     [self.viewWithdraw addSubview:withdrawCheckBox.view ]; 
     withdrawCheckBox.labelCheckBox.textColor = [UIColor blackColor];
     withdrawCheckBox.labelCheckBox.font = [UIFont systemFontOfSize:14];
     withdrawCheckBox.labelCheckBox.text = @"Withdraw";   

     [withdrawCheckBox setCheckBoxSelected:YES];
 }

The above code is 'Disable' the button, but it (Remove/ Hide) the 'check mark Picture' inside the button.Why?

All links ( outlet + Actions ) are connected .

What obvious thing am I missing? Thanks.

Upvotes: 0

Views: 2197

Answers (3)

jrturton
jrturton

Reputation: 119272

You have defined the button in interface builder. It looks like you havent set the image for all control states - select the button and look at the attributes inspector - there is a drop down for normal, highlighted, etc. is your check mark image defined for all those states?

Upvotes: 0

Mario
Mario

Reputation: 4520

What exactly are you trying to do? Maybe setting userInteractionEnabled is what you want? Cheers

Upvotes: 1

rdelmar
rdelmar

Reputation: 104082

This looks way too complex for what you want to do. You have a reference to your button -- checkBoxButton. Just use checkBoxButton.enabled = NO;

Upvotes: 0

Related Questions