Amazon.com Widgets iPhone Buttons
Welcome, Guest. Please login or register.
Did you miss your activation email?
May 24, 2013, 06:04:07 PM
Home Help Search chat Login Register   
News: Read this please.The Great Kangaroo Escape Looking for reviews of the 4th ed on Amazon!   Twitter:  @skochan
                     

+  Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
|-+  Old Stuff
| |-+  Help!!!
| | |-+  iPhone Buttons
Pages: [1]   Go Down
Print
Author Topic: iPhone Buttons  (Read 906 times)
lexy0202
Guest




« on: April 13, 2009, 01:38:56 PM »

Hi there,
I would first of all just like to say that this website and book is the best ever... I have never read such an amazingly useful and easy to understand book and the support and discussion on this forum is really good,  Cheesy
Sorry that this is nothing to do with any of the questions/examples, but please could you tell me how to disable a button (either make it invisible, or unavailable for the user to tap (grayed-out))?
e.g
//beginning of example code
-(IBAction) click2: (id) sender
{
   ++score;
    [displayString setString: [NSString stringWithFormat: @"%i", score]];
   [display setText: displayString];
   if (score == 100)
   {
      [display setText: @"Player 2 Wins!"];
                // Disable button here please!
   }
   else
   {}
}
//end of example code
I had an idea that you might send a message to the 'sender', or edit the sender's properties (the sender being UIButton (subclass of UIControl))
I had a look in the docs and couldn't find anything apart from enable which I couldn't figure out how to use!

I know this is probably painfully simple  Embarrassed, but could someone please help me out here!  Huh

Alex
Logged
skochan
Administrator
Hero Member
*****
Posts: 3106







« Reply #1 on: April 13, 2009, 02:47:34 PM »

Alex,

Controls have an inherited property called enabled that can be set to YES or NO.  You want to disable the button that is pressed and not the label, so your click2: method should look like this:

-(IBAction) click2: (id) sender
{
   UIButton *myButton = (UIButton *) sender;

   ++score;
   [displayString setString: [NSString stringWithFormat: @"%i", score]];
   [display setText: displayString];
   if (score == 100)
   {
      [display setText: @"Player 2 Wins!"];
      myButton.enabled = NO;         // Disable button here please!
   }
   else
   {}
}

Try that and let me know the result!

Cheers,

Steve K.
« Last Edit: April 13, 2009, 02:49:45 PM by skochan » Logged
esc
Global Moderator
Full Member
*****
Posts: 230






« Reply #2 on: April 13, 2009, 05:15:27 PM »

Alternately, if you want to make the button invisible, UIButton is also a subclass of UIView, so you can use the property "hidden" to hide the button Smiley
Logged
lexy0202
Guest




« Reply #3 on: April 14, 2009, 03:52:24 AM »

Thanks guys, that really helped.  Cheesy
Unfortunately, I also need to know how to disable Player 2's button as well, seeing as the other guy's button is not a sender, how do you disable that?
Secondly, how do you create a method - e.g a Play Again button, to reset  both the buttons to being enabled?
Finally, is it possible to flip both the buttons inside IB? If so how?

Thanks again

Alex
Logged
lexy0202
Guest




« Reply #4 on: April 14, 2009, 05:08:21 AM »

OK, I fixed all my problems by adding Outlets to the desired GUI objects, however there is still one problem:
The line of code I use to rotate my objects, is this:
display.transform = CGAffineTransformMakeRotation( M_PI );
The display bit can be changed to player1, for player1's button, player2, for their button, or playAgain, will change the rotation of the playAgain button. Using display changes it's rotation (used for if player1 wins, it will flip to face player1 and tell him/her that they have won.)
However, this appears to only work one way, and I cannot work out what the ( M_PI ) is doing. So I cannot change it to do the reverse.
Please could someone help me out

Thanks,
alex
Logged
lexy0202
Guest




« Reply #5 on: April 14, 2009, 02:18:27 PM »

OK, fixed by setting the parameter to 0!
Logged
Pages: [1]   Go Up
Print
Jump to:  



Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents (c) 2009 classroomM.com. All rights reserved.