1

How would I go about turning the first button back on from the second button [self firstButton:sender.enabled = Yes]; only works to turn it off. Which the compiler gives me a warning about turning the button off that way. So if there is a better way to turn it off from the second button to please let me know how to turn it on and off..

-(IBAction)firstButton:(UIButton *)sender{
if(firstButton is clicked){
//Turn firstButton off
((UIButton *)sender).enabled = NO;
}
}

-(IBAction)secondButton:(UIButton *)sender{
if(secondButton is clicked)
{
//Turn firstButton BACK ON?
[self firstButton:sender.enabled = Yes];
}
}

Thanks!!

Bug
  • 2,576
  • 2
  • 21
  • 36
Petahwil
  • 417
  • 1
  • 4
  • 16
  • you should create reference pointers to the buttons... – holex Aug 29 '13 at 22:22
  • how would you go about that @holex? – Petahwil Aug 29 '13 at 22:35
  • So this is all real new to me I am coming over from java.. How do I set the tag references to the *firstButton @0x7fffffff? I cant seem to figure out how to use the tag from the *otherButton and shut off the *firstButton. – Petahwil Aug 30 '13 at 01:03
  • @Petahwil, as far as I'm seeing, _Joel_ has a good suggestion for you. – holex Aug 30 '13 at 08:05

2 Answers2

2

You can set ivars for each button using IBOutlet

IBOutlet UIButton *firstButton, *secondButton;

Then link them to the correct button in Interface Builder.

Then you can use these IBActions to accomplish what you're looking for.

-(IBAction)firstButtonClicked:(id)sender
{
    [firstButton setEnabled:NO];
}

-(IBAction)secondButtonClicked:(id)sender
{
    [firstButton setEnabled:YES];
}
Joel
  • 15,654
  • 5
  • 37
  • 60
1

Are you trying to toggle the state of the other button from each button? If so, this should help. First use viewWithTag: to get a reference to the other button. This will require that you properly assign the tag property of each button to the same tags as specified below. Then, you can simply set the buttons enabled state to ! its current enabled state. Which will toggle it. on to off, off to on.

-(IBAction)firstButton:(UIButton *)sender
{
    UIButton *otherButton = (UIButton *)[self.view viewWithTag:33];
    [otherButton setEnabled:!otherButton.enabled];
}

-(IBAction)secondButton:(UIButton *)sender
{
    UIButton *otherButton = (UIButton *)[self.view viewWithTag:44];
    [otherButton setEnabled:!otherButton.enabled];
}
Mick MacCallum
  • 129,200
  • 40
  • 280
  • 281