Domanda

I've setup a UISlider to accept values from 0 to 10. I want to be able to have the slider execute static commands for each increment of the UISlider value, from 0 to 10. I've linked the UISlider with a button called zoomControl. For example, I want to do something like this:

- (IBAction)zoomControl
{
    if(zoom.selectedSegmentIndex == 0)
    {
        // execute commands
    }

    else if(zoom.selectedSegmentIndex == 1)
    {
        // execute commands
    }

    else if(zoom.selectedSegmentIndex == 2)
    {
        // execute commands
    }

// + all the remaining statements up to 10
}

This was the declaration of the UISlider, made in the .h file, as well as the button:

@interface ViewController : UIViewController

{
    IBOutlet UISlider *zoom;
}

- (IBAction)zoomControl;

The errors that I'm experiencing now have to do with the selectedSegmentIndex block. What is the correct syntax for the UISlider?

(The selectedSegmentIndex block was the syntax for the UISegmentedControl switch)

È stato utile?

Soluzione

You are using a property of UISegmentedControl named selectedSegmentIndex, where you need to access the value property of UISlider.

use instead zoom.value

try

if ((int)(zoom.value + 0.5) == 0) { //do something...}

I've added 0.5 to round the value when type casting it to an int because zoom.value is of type float.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top