1

当用户滑动它向前移动的滑块并在标签中更改其值时,我正在执行 uislider 的应用程序 haivng 功能。我为此采取了这样的行动

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

到这里为止很好,但是当用户第一次开始点击滑块时,我需要显示警报视图。如果用户单击确定,则它的标签应该更改滑块值,如果取消它应该显示一些默认值。需要的关键点:

  1. 如果用户点击第二次警报,则仅显示一次警报现在应该显示
  2. 如果在警报视图上单击确定,则只有滑块应更改
  3. 如果在警报视图上单击取消,则滑块不应更改其值
4

3 回答 3

2

1)查看dispatch_onceAPI。看看这个链接

2) 和 3) 在实例变量中抛出警报之前保存滑块的值。将您的类设置为 UIAlertView 的代表。如果点击取消按钮,请将滑块设置回保存的值。如果点击 OK 按钮(您必须在创建警报时指定),则什么也不做。

对于 UIKit 入门,请参阅 Ray Wenderlich 的网站

于 2015-03-25T15:44:25.883 回答
0

我宁愿让您的 viewController 成为 UISlider 的代表,并管理自己的状态以显示/隐藏警报。

检查您需要实现的 UISliderDelegate 方法(如果您不这样做,编译器会抱怨)。

@interface YourViewController : UIViewController <UIScrollViewDelegate>
于 2015-03-25T16:19:27.113 回答
0

这是你的答案:

> - (IBAction)valueChanged:(UISlider *)sender
{
static dispatch_once_t onceToken;

dispatch_once (&onceToken, ^{

    UIAlertController * alert=   [UIAlertController
                                  alertControllerWithTitle:@"Title"
                                  message:@"Your custom message"
                                  preferredStyle:UIAlertControllerStyleAlert];

    UIAlertAction* cancel = [UIAlertAction
                         actionWithTitle:@"Cancel"
                         style:UIAlertActionStyleDefault
                         handler:^(UIAlertAction * action)
                         {
                             //Do some thing here
                             [alert dismissViewControllerAnimated:YES completion:nil];
                             return ;

                         }];
    [alert addAction:cancel];

    UIAlertAction* ok = [UIAlertAction
                         actionWithTitle:@"OK"
                         style:UIAlertActionStyleDefault
                         handler:^(UIAlertAction * action)
                         {
                             //Do some thing here
                             [alert dismissViewControllerAnimated:YES completion:nil];

                         }];
    [alert addAction:ok];

    [self presentViewController:alert animated:YES completion:nil];

});

}
于 2015-03-25T15:58:48.667 回答