disable the click event of button in iPhone - iphone

I am new to iPhone development.
In my application,
i want to disable the click event of button when it pressed first time by the user.
for that purpose
i tried
buttonname.Enable=FALSE;
But the image of button also goes washed like a disable.
i Want to show Image properly and button should be disabled, both at time.
what to do?
Please help me.
Thanks For Your Time.

Set buttonname.userInteractionEnabled = NO; This will disable the action of the buttonname but the UIButton will be shown. Only the clicked event will not work.

Use this code it may help you
[buttonName addTarget:self action:nil forControlEvents:UIControlEventTouchDown];

Try setting its userInteractionEnabled property to NO.

Related

set UIButton's image in interface builder for differen state

I am facing very strange issue.
In interface builder I am trying to set images for "normal" state config and for "selected" state config. but by clicking the button my image is not getting changed.
even I write the code in viewDidLoad method.
[btnCheckBoxMale setImage:[UIImage imageNamed:#"blankcheckbox.png"] forState:UIControlStateNormal];
[btnCheckBoxMale setImage:[UIImage imageNamed:#"checkbox.png"] forState:UIControlStateSelected];
but my images are not getting changed on cliking on it
can anyboday say what is the problem?
Set the image to different states in interface builder instead of setting it in code. Please see the screenshot for how to set it. Try this & if you are facing any problem then ask me.
It will work if you set manually in button action:
btnCheckBoxMale.selected = YES;
Because by default UIButton has only two states - Normal and Highlighted. And other states like selected and disabled you have to control manually.
just set selected when you call the method on button click event.. for example..
-(IBAction) btnCheckBoxMale_Clicked:(id)sender{
[btnCheckBoxMale setSelected:YES];
}
-(IBAction) btnCheckBoxMale_Clicked:(id)sender{
UIButton * btnCheckBoxMale = (UIButton *)sender;
[btnErase setSelected:! btnCheckBoxMale];
}

iPhone:navigation bar "back" button clickable = NO?

I know that we can hide navigation bar "back" button. But I dont whant to hide it ! Is there any way to make it just not clickable ?
You can not disable the backBarButtonItem. Setting enabled property of backBarButtonItem to NO doesn't actually disables it.
It seems Apple prevented others("us") from disabling backBarButtonItem, even it ignores the target and action set to backBarButtonItem.
try this
self.navigationItem.leftBarButtonItem.enabled=NO;
self.navigationItem.backBarButtonItem.enabled=NO;
Update:
It seems to be Apple doesn't allow the back button to enable / disable. Instead of that we can hide it.
self.navigationItem.hidesBackButton = YES;
self.navigationItem.backBarButtonItem.enabled = NO;
Disable:
self.navigationItem.leftBarButtonItem.enabled = NO;
Enable:
self.navigationItem.backBarButtonItem.enabled = YES;
The default cancel button cannot be disabled as Apple does not allow this feature.
This doesn't work with the default back button.but it's possible to hide the default back button [self.navigationItem setHidesBackButton:YES];
Yes, you can disable that button, just setenabled property of that button to NO.
Should be possible to disable the button:
backButton.enabled = NO;
Apple does not want you to disable it but you can hide it of course.
self.navigationItem.hidesBackButton = YES;
This especially works well if you have a custom UIBarButtonItem as a button.
In stock applications you would notice features that are not applicable are hidden altogether rather than disabled.

iPhone - UIButton - background image for disabled

I have UIButton that I set the background image for three states, normal, highlighted, and disabled, all with the following format:
[button setBackgroundImage:buttonBGD forState:UIControlStateDisabled];
My problem is, that when the button is disabled, the iPhone chooses to lighten the image for me. Which isn't desired. But if I tell it:
[button setAdjustsImageWhenDisabled:NO];
Then the image doesn't change at all. How do I remove the automatic lightening of the image, and instead use just the original image I created?
Try:
[button setBackgroundImage:buttonBGD forState:UIControlStateNormal | UIControlStateDisabled]
If you want the same disabled image when the button is selected and disabled, then add:
[button setBackgroundImage:buttonBGD forState:UIControlStateSelected | UIControlStateDisabled];
Hope that helps!
Actually this are the constraints made by apple and as such there is no work around way. But u can try using the custom button and try using a bit more dark image then required in disabled state so that when it gets lightened then it is up to the mark as per your requirements.
Hope this helps.
Try removing the selected state while disabled:
[button setSelected:NO];

how to disable user interaction for a button

i have a play button in my view,if i press play its gets updated the stream and started playing..
until i get play song i dont want to take any user interactions on play button..
can any ony help me on this.....
button.userInteractionEnabled = NO;
You could also set the "Enabled" property to "NO" or if you want animation, fade the alpha out.

iPhone app Action Button

I need to add an action button in my iPhone application. When that one is clicked the UIActionSheet with buttons need to be popped up.
Can any one tell me how to add an action button? - means is there any in built action button for iPhone app? or do we need to create a new button with image?
Thanks in advance!
Assuming this is in a view controller, you can do something like:
- (void)viewDidLoad
{
UIBarButtonItem *actionButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemAction
target:self
action:#selector(methodThatShowsSheet)];
self.navigationItem.rightBarButtonItem = actionButton;
[actionButton release];
}
(Pardon the weird indentation to make it fit in a reasonable width (I normally just let Xcode wrap-indent everything automatically)).
See Nick Veys' answer for how to implement methodThatShowsSheet.
You need to hook up the action from the button you've decided will present this action sheet to code that shows it.
See the Apple Documentation on UIActionSheet for help on doing that.
I'm not sure I understnd your question but UIKit includes the UIButton class which will automatically send a message (specified by you) to an object (also specified by you). You can create a UIButton i nInterface builder or programatically.
Without more details on whay you actually want to do or why you're finding it difficult,m it's difficult to be more precise.