【问题标题】:how to set indicator of picker view to specific value如何将选择器视图的指示器设置为特定值
【发布时间】:2015-11-16 06:58:05
【问题描述】:

当您单击按钮时,我的单元格包含一个按钮,选择器视图将像下面的图片一样弹出操作

问题:

如何更改以使指示器移动到按钮中显示的正确值。

例如,我的按钮显示为 8,如果您点击它,将弹出选择器视图,指示器选择 8。

如果您知道如何自定义它。请就这个问题给我建议。谢谢

【问题讨论】:

    标签: iphone uipickerview


    【解决方案1】:

    您可以执行以下操作:

    - (void)selectRow:(NSInteger)row inComponent:(NSInteger)component animated:(BOOL)animated
    

    您可以通过为按钮添加 IBAction 来使用它。

    -(IBAction)userTappedNumber{
        //Call your picker view's method here.
        [self.pickerView selectRow:8 inComponent:0 animated:YES];
    }
    

    为了将来参考,请尝试查看 Apple 的参考资料,并在提出简单问题之前通过 google 和 Stack Overflow 搜索搜索类似问题。 Apple's UIPickerView Class Reference

    【讨论】:

      【解决方案2】:

      使用这个方法

      - (void)selectRow:(NSInteger)row inComponent:(NSInteger)component animated:(BOOL)animated
      

      【讨论】:

        【解决方案3】:

        有一种方法可以在不知道特定值在数组中的位置的情况下找到它。

        首先,将要查找的值转换为字符串

        stringValue = [NSString stringWithFormat:@"%d",intValue];
        

        其次,创建一个循环来查找数组中的值并选择它:

        int i = 0;
            for(NSString* number in arrayName)
            {
                if ([stringValue isEqualToString:number]){
                    [pickerViewName selectRow:i inComponent:0 animated:YES ];
                }
                i++;
            }
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2017-09-05
          • 2012-03-24
          • 2019-09-08
          • 2015-09-07
          相关资源
          最近更新 更多