UISlider not getting called when it ends sliding - ios

I am using UISlider in my project, but I want to fire event when user end dragging the Slider.
I have following code.
[progressBar addTarget:self
action:#selector(sideProgressBarValueChanged)
forControlEvents:UIControlEventValueChanged];
- (void) sideProgressBarValueChanged
{
NSLog(#"Changing values");
// Some action
}
I set this setContinuous to false.
[progressBar setContinuous:false];
but sometimes its not getting call.
I am confused that what else should I use to perform accurate results.
Can anybody suggest something?

Related

Calling a button click event in another function iOS objective-c

I have a trigger to catch the button click on my controller like this
[saveButton addTarget:self action:#selector(save:) forControlEvents:UIControlEventTouchUpInside];
and the relevant function is
- (void)save:(id)sender {
//implementation code
}
How do call this function in another function, I try to call this function like as follow but it showing error.
(void)checkStatus{
if(somecondition){
[self save];
}
}
Note that I am new to iOS and Objective-C and I am editing a code of another developer. Please give me a solution.
your button action has a parameter , so you need to append in the parameter as nil or self.do like
- (void)checkStatus{
if(somecondition){
[self save:nil];
}
}

Setting UIButton Enabled and setting an Image for each state is not working

I have a viewController which contains a button. I am showing this view controller over another viewController not modal, but via
[self.storyboard instantiateViewControllerWithIdentifier:#"MyButtonView"]
So the result is one viewController floating over the another viewController, where the top viewController only takes up about half the screen.
The bottom view controller at certain times, tells the top viewController to disable and enable its button. When this call happens (and yes it is happening because I am debugging it). The button is not being enabled or disabled.
=== This is in my viewdidload method =====
[self.myCirlceButton setImage:[UIImage imageNamed:#"Checkmark_v1_normal.png"] forState:UIControlStateNormal];
[self.myCirlceButton setImage:[UIImage imageNamed:#"Checkmark_v1_selected.png"] forState:UIControlStateHighlighted];
[self.myCirlceButton setImage:[UIImage imageNamed:#"Checkmark_v1_disabled.png"] forState:UIControlStateDisabled];
=== These are delegate method on the top viewController that get called by the bottom viewcontroller ===
-(void)enableConfirmArrow
{
[self.myCirlceButton setEnabled:YES];
}
-(void)disableConfirmArrow
{
[self.myCirlceButton setEnabled:NO];
}
When I break point on enable and disable methods the self.myCircleButton is NOT nil.
I have no idea why the UI is NOT updating? The only thing I can think of is the above enable and disable methods sometimes get called back and forth about 10 times in 3 seconds.
/// UPDATE ///
As a test I changed the following and it does remove it. More proof that the disable is being called.
-(void)disableConfirmArrow
{
[self.myCirlceButton setEnabled:NO];
[self.locationCirlceButton removeFromSuperview];
}

Passing parameters into a selector

I have an UIButton that is subview on an UIView. When the button is pressed, my app is supposed to pass a captured image into a function called by the #selector. However, my research shows me that I am not able to pass anything to the function with the selector of the UIButton. How can I go around this?
[hangButton addTarget:self
action:#selector(faceDetector: the image I want to pass in)
forControlEvents:UIControlEventTouchUpInside];
You should trigger your events within a handleButton press method. You don't preset arguments, buttonPress selectors pass one argument, the button that is sending the event.
[hangButton addTarget:self
action:#selector(handleButtonPress:)
forControlEvents:UIControlEventTouchUpInside];
- (void) handleButtonPress:(id)sender {
UIImage * imageToFaceDetect = // get your image
[self faceDetector:imageToFaceDetect];
}

How to make a START/STOP button for an iOS app

just wondering how to make a button "START" that when pressed triggers a function and the text changes to "STOP". then when pressed again the function will stop and the text changes back to "START"
Ive got the button already that starts the function. and i can handle changing the title, just not sure on what to use to make the 1 button have 2 functions
Add the IBAction method like:
- (IBAction)buttonTapped:(id)sender
{
UIButton *btn = (UIbutton *)sender;
NSString *title=btn.titleLabel.text;
if ([title isEqualToString:#"Start"])
{
//Start
}else
{
//Stop
}
}
Please try this:
- (IBAction) buttonAction:(id)sender
{
if([[(UIButton *)sender currentTitle]isEqualToString:#"START"])
{
[actionButton setTitle:#"STOP" forState:UIControlStateNormal];
//start the action here and change the button text to STOP
}
else if([[(UIButton *)sender currentTitle]isEqualToString:#"STOP"])
{
[actionButton setTitle:#"START" forState:UIControlStateNormal];
//stop the action here and change the button text to START
}
}
you have at least two options here:
Check for the title of your button and depending on the value call an action or the other.
Create two different buttons, each one with his action and show/hide them.

Multiple tap on UIButton and access different behavior of Button

I create a project of the Multiple user can tapped on the different button.
Following problem may phase,
I implement the gestureRecognizer and it's proper work but how get the which button tapped by the user for that to access those button event's
following screen shows the button,
Following is the code for gestureRecognizer delegate method so, how to get the button event and how to manage it,
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
if ([touch.view isKindOfClass:[UIButton class]]) {
NSLog(#"Button is pressed");
if (tag == 1) {
NSLog(#"Button1 is pressed");
}
return NO;
}
return YES;
}
following method for the IBAction method to touch when the button tapped
-(IBAction)btnPress:(id)sender{
tag=[sender tag];
NSLog(#"%i",tag);
}
But here issue is first call the gestureRecognizer delegate method then IBAction method to how to solve this problem,
Thanks in advance for your valuable time spend on my problem,
Thaks and regards
Neon Samuel.
If the button is instance of UIButton, then you do not need to use gestureRecognizer at all.
Try to set addTarget:action to get callback when user click that UIButton:
[button1 addTarget:self action:#selector(btnPress:)];
[button2 addTarget:self action:#selector(btnPress:)];
If you have already set tag value to each button, then your IBAction method would work properly.
-(IBAction)btnPress:(id)sender{
NSInteger tag=[sender tag];
NSLog(#"%d",tag);
}

Resources