0

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.

0

3 Answers 3

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

i want 'check mark' appear and the button 'disable' in the same time when (Didload) the View !!
0

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?

1 Comment

I am missing the picture of 'Disabled' state. Thank you So Much !
0

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

6 Comments

What did it do? Nothing? Something? I don't see anything in your CheckBox class that's doing anything useful (is that class doing other things that you didn't show?). Why not just put the IBOutlet to checkBoxButton in your "another view controller" and use the line I said in my answer. That will work.
when i click in the button, 'Check Mark picture' will appear , and on click , the 'check mark picture' will hide !!
Do you mean the check mark appears and disappears when you click the button? If so, that's what it's supposed to do. What behavior are you looking for?
exactly ! i want 'check mark' appear and the button 'disable' in the same time when (Didload) the View !!
Put in as the first line of your setCheckBoxEnabled method, NSLog(@"%@",self.checkBoxButton); and tell me what the log shows
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.