iosobjective-cuialertviewuislideruicontrolevents

IOS:Show alert only once if UISlider changes its value


i am doing app haivng functionality of uislider when user slides the slider it moves forword and chages its value in the label.I have given action like this for that

- (IBAction)sensivity:(UISlider*)sender
{
    self.senlabel.text =[NSString stringWithFormat:@"%d", (int)sender.value];
} 

upto here its fine but i need to show the alert view when user starts to tap the slider for first time. if user click ok then it label should change the slider value if cancel it should show some default value . Key points needed:

  1. show alert for only time if user taps second time alert should now show
  2. if click ok on alert view then only slider should change
  3. if click cancel on alert view then slider should not change its value

Solution

  • 1) Look at the dispatch_once API. Check out this link.

    2) and 3) Save the value of the slider right before you throw the alert up in an instance variable. Set your class to be the delegate of the UIAlertView. If the cancel button is hit, set the slider back to the saved value. If the OK button is hit (which you must specify when creating the alert), do nothing.

    For a UIKit primer, see Ray Wenderlich's site.