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 05-26-2009, 07:58 PM   #1 (permalink)
.38 special tucked
 
Join Date: Apr 2009
Location: Brooklyn, NY
Posts: 133
mr-sk is on a distinguished road
Default Disabling a UIButton

Yes, I've read both this thread: http://www.iphonedevsdk.com/forum/ip...-uibutton.html
and this: http://www.iphonedevsdk.com/forum/ip...n-disable.html

None of the code works. Here's what I'm doing:

.h
Code:
    IBOutlet UIButton *addButton;
@property (nonatomic, retain) IBOutlet UIButton *addButton;

- (IBAction)addToFav:(id)sender;
.m

Code:
- (IBAction)addToFav:(id)sender
{    
    NSLog(@"Add Button Pressed");    
    addButton.enabled = FALSE;
    addButton.alpha = 0.5f;
}
Any idea? I just want to disable the button after a user selects it.

Thanks,

- sk
mr-sk is offline   Reply With Quote
Old 05-26-2009, 08:28 PM   #2 (permalink)
Registered Member
 
Join Date: Jan 2009
Posts: 280
dapis is on a distinguished road
Default

Quote:
Originally Posted by mr-sk View Post
Yes, I've read both this thread: http://www.iphonedevsdk.com/forum/ip...-uibutton.html
and this: http://www.iphonedevsdk.com/forum/ip...n-disable.html

None of the code works. Here's what I'm doing:

.h
Code:
    IBOutlet UIButton *addButton;
@property (nonatomic, retain) IBOutlet UIButton *addButton;

- (IBAction)addToFav:(id)sender;
.m

Code:
- (IBAction)addToFav:(id)sender
{    
    NSLog(@"Add Button Pressed");    
    addButton.enabled = FALSE;
    addButton.alpha = 0.5f;
}

Any idea? I just want to disable the button after a user selects it.

Thanks,

- sk
Well for starters, the line:
@property (nonatomic, retain) IBOutlet UIButton *addButton;

can be just:
@property (nonatomic, retain) UIButton *addButton;


Also, did you include in your .m file the line:
@synthesize addButton;

You need to have accessor methods to set properties of addButton.
dapis is offline   Reply With Quote
Old 05-26-2009, 08:34 PM   #3 (permalink)
.38 special tucked
 
Join Date: Apr 2009
Location: Brooklyn, NY
Posts: 133
mr-sk is on a distinguished road
Default

Thanks for the response -

Yes, I did include synthesize. I can't seem to change it in any way, including the color:

Code:
    addButton.backgroundColor = [UIColor grayColor];
I'll remove the IBOutlet declaration now and try again ..... ok, still no luck.

- sk
mr-sk is offline   Reply With Quote
Old 05-26-2009, 08:38 PM   #4 (permalink)
Registered Member
 
Join Date: Jan 2009
Posts: 280
dapis is on a distinguished road
Default

Quote:
Originally Posted by mr-sk View Post
Thanks for the response -

Yes, I did include synthesize. I can't seem to change it in any way, including the color:

Code:
    addButton.backgroundColor = [UIColor grayColor];
I'll remove the IBOutlet declaration now and try again ..... ok, still no luck.

- sk
Well, the next most likely thing that comes to mind is that you may not have linked the button in Interface Builder to the addButton in File's Owner. You might want to check that.
dapis is offline   Reply With Quote
Old 05-26-2009, 08:44 PM   #5 (permalink)
.38 special tucked
 
Join Date: Apr 2009
Location: Brooklyn, NY
Posts: 133
mr-sk is on a distinguished road
Default

Hey,

The NSLog message I have gets fired off when I click the button, thus Im assuming its wired correctly.

- sk
mr-sk is offline   Reply With Quote
Old 05-26-2009, 09:03 PM   #6 (permalink)
Registered Member
 
Join Date: Jan 2009
Posts: 280
dapis is on a distinguished road
Default

Quote:
Originally Posted by mr-sk View Post
Hey,

The NSLog message I have gets fired off when I click the button, thus Im assuming its wired correctly.

- sk
That's no guarantee that you can access the properties of the button. That just means that the button is properly wired to the selector for the message in question. It is crucial that in Interface Builder you connect the button in the nib to the corresponding IBoutlet name in File's Owner. Your response makes me think that this is almost certainly your problem.

If you don't know how to do this, open your nib (by double-clicking it in X-code) in Interface Builder. Now control-click on Files Owner. You should see 'addButton' listed under the outlets. Drag from the circle next to that over to the corresponding button in the nib.
dapis is offline   Reply With Quote
Old 05-26-2009, 09:32 PM   #7 (permalink)
.38 special tucked
 
Join Date: Apr 2009
Location: Brooklyn, NY
Posts: 133
mr-sk is on a distinguished road
Default

Dapis - right on man. I didn't have the IBOutlet setup correctly in the file owner. Thanks.

I'm only about a month into iphone programming, and IB is very new to me even as a traditional engine coder.

Thanks again!
mr-sk is offline   Reply With Quote
Old 06-26-2009, 10:09 PM   #8 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 15
Arastu is on a distinguished road
Default Thanks guys for this great post

Hi guys
I was having the same trouble with disabling and enabling my buttons...I read through this and wallaa...my issue resolved.Thanks a lot.


Arastu



Quote:
Originally Posted by mr-sk View Post
Dapis - right on man. I didn't have the IBOutlet setup correctly in the file owner. Thanks.

I'm only about a month into iphone programming, and IB is very new to me even as a traditional engine coder.

Thanks again!
Arastu is offline   Reply With Quote
Old 01-12-2012, 09:44 PM   #9 (permalink)
fou
Registered Member
 
Join Date: Jan 2012
Posts: 1
fou is on a distinguished road
Default

Hi,

I am able to create buttons, link functions to them, and it also seems i'm able to disable a button (because i forgot to enable it back and i couldnt click on it. My question refers to how, while a button is disabled, you can still click on it and the click will be queue until the button is enabled and the button click will then proceed and process the click.

how do i make sure nobody can click or queue some clicks while a button is disabled?

Thanks!
fou is offline   Reply With Quote
Old 01-12-2012, 10:24 PM   #10 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by fou View Post
Hi,

I am able to create buttons, link functions to them, and it also seems i'm able to disable a button (because i forgot to enable it back and i couldnt click on it. My question refers to how, while a button is disabled, you can still click on it and the click will be queue until the button is enabled and the button click will then proceed and process the click.

how do i make sure nobody can click or queue some clicks while a button is disabled?

Thanks!
A disabled button does not queue clicks. It ignores them. If you disable a button, the user clicks it 5 times, then 2 seconds later, you enable it again, it's as if the user never clicked the button at all.

If you want a system where button clicks get queued up and fire later you would have to jump through some hoops to do it.

What I would probably do is to leave the button active, but put logic in the action method to record button clicks. I'd also change the settings on the button so it doesn't highlight when clicked.

On the other hand, I don't think I'd make an app that queues button clicks and fires them later. It sounds like a poor, confusing user interface.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Reply

Bookmarks

Tags
add, uibutton

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: 341
5 members and 336 guests
givensur, ipodphone, jbro, mer10, yomo710
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,649
Threads: 94,113
Posts: 402,881
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Anwerbl
Powered by vBadvanced CMPS v3.1.0

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