Okay. In Xcode, I want my application to run a line of code once the UISlider gets to 1.00 or the end of the slider. How would I do this?
A:
Write an IBAction method, and connect it to your UISlider in Interface Builder, selecting "On Changed Value" in the dialog that will appear. Then add some code like this to the method:
if(mySlider.value == 1.0f){
//Insert your code here
}
--James
James
2010-01-29 22:44:15
When I put this code as the action for the IBAction it says that mySlider is undeclared. How do I fix this? (Sorry, I'm new to coding)
iTz Sillohsk8
2010-01-29 23:00:40
You need to create an instance of UISlider in your .h file, declare it as a property, and synthesize it in your .m file. mySlider is just an arbitrary name I chose, it could be anything. Once you have done the above, you need to link the uislider you added in interface builder to the instance of uislider your created in your .h file. Then this should work. Google UISlider tutorial, and see if you can find some good code samples there.
James
2010-01-29 23:16:53
+1
A:
Add these to your UIViewController.
In your .h, below the interface:
-(IBAction)sliderChangedValue:(id) sender;
In your .m:
-(IBAction)sliderChangedValue:(id) sender {
if([sender isKindOfClass:[UISlider class]]) {
UISlider *slider = (UISlider *)sender;
if(slider.value == 0.0 || slider.value == 1.0) {
//your line of code
}
}
}
Then in Interface Builder connect Value Changed of your UISlider to this method.
David Kanarek
2010-01-30 01:51:04
Can you do me a huge favor and upload the source code to megaupload or something? I get 5-6 errors everytime I do this.
iTz Sillohsk8
2010-01-31 00:49:43
The problem is that some of this has to be done in Interface Builder and you wont see it any better than what I can describe here. To make connections in IB, open the inspector, choose the third tab, and drag from the Value Changed circle to the File's Owner item in the main window. Let go and a pop up will appear. Choose sliderChangedValue from the popup. It will only appear after copying this code to your UIViewController and saving the .h file.
David Kanarek
2010-01-31 01:14:13