Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 09-11-2011, 06:20 PM   #1 (permalink)
Registered Member
 
Join Date: Jul 2011
Posts: 42
xcoderx is on a distinguished road
Default Have a button stop working when my labels text = 0?

Hey guys i have a label and you can + or - 1 from the label so its like a counter. And when it hits 0 from subtracting so many times, I want the button to stop working. I got it to do this. But my problem is getting the button to start working again after the value is anything greater than 0. Here is my code:

Code:
 - (IBAction)subtractButton:(id)sender {
    int val = [label.text intValue];

    [label setText:[NSString stringWithFormat:@"%d",[label.text intValue] -1]];  
    
    if(val - 1 <= 0) { 
        UIButton *button = (UIButton *)sender;
        [button setEnabled:NO]; 
    }
}
Thanks in advance for all the help everybody!

Last edited by xcoderx; 09-11-2011 at 06:21 PM. Reason: Had to fix the code i forgot to put something in it
xcoderx is offline   Reply With Quote
Old 09-11-2011, 07:29 PM   #2 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 577
Speed is on a distinguished road
Default

Judging by what you have here, I will assume that you have an "add" method. Whenever you add something using that button, you will be always greater than, or equal to zero if you subtract - hence you can just enable the subtractionButton whenever you add something.

Code:
 - (IBAction)addButton:(id)sender {
    
    // ...

    if (![button enabled]) [button setEnabled:YES]; 

}
Speed is offline   Reply With Quote
Reply

Bookmarks

Tags
iphoen, method calling, objective c, uibutton, uilabel

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 403
10 members and 393 guests
7twenty7, apatsufas, Eclectic, eski, fiftysixty, JackReidy, teebee74, tim0504, UMAD, yuncarl28
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,672
Threads: 94,121
Posts: 402,904
Top Poster: BrianSlick (7,990)
Welcome to our newest member, yuncarl28
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 05:04 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0