如果我在选择器旋转时用完成按钮关闭UIPickerview的Actionsheet,则获取null值

问题描述 投票:1回答:3

我有一个UIActionSheet包含pickerUIToolbar。在UIToolBar上有一个完成按钮。然而,当我旋转Picker组件并且在它停止旋转之前,如果我点击Done按钮然后我在我的UITextfield没有任何价值。如果我在选择器停止旋转动画后点击Done按钮,那么我将获得所选组件的值

有没有办法在停止动画之前获得项目的价值..?

解决

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
     UILabel *lbl = (UILabel *)view;

           // Reuse the label if possible...
           if ((lbl == nil) || ([lbl class] != [UILabel class])) {
               CGRect frame = CGRectMake(0.0, 10.0, 250, 50);
               lbl = [[[UILabel alloc] initWithFrame:frame] autorelease];
           }
    if (component == 0) {

        lbl.textColor = [UIColor blackColor];
        lbl.textAlignment=UITextAlignmentLeft;
        lbl.backgroundColor = [UIColor clearColor];



        lbl.text = [arrCountry objectAtIndex:row];
        lbl.font=[UIFont boldSystemFontOfSize:14];
         NSInteger clm1 = [pickerView2 selectedRowInComponent:component];


        txtCountry.text = [arrCountry objectAtIndex:clm1];
        countryCode=[arrCountryCode objectAtIndex:clm1];
    }

    return lbl;
}

并且

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{

  txtCountry.text = [arrCountry objectAtIndex:row];
  countryCode=[arrCountryCode objectAtIndex:row];
}
iphone objective-c ios uipickerview
3个回答
2
投票

我认为你不能交配。当微调器停止时,UIPicker只调用didselectrow,否则它会卡在先前拾取的行上。在你的情况下的第一个。

您可以使用uipicker获得最接近的功能的是此委托方法:

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view

您必须查看屏幕上的视图及其与中心的偏移量。除此之外,您可以实现自己的滚动视图并使用uipicker叠加层,但这涉及大量工作。

要么!你可以告诉你的用户以正确的方式使用uipicker lol。

阻止用户按下保存的另一种方法是检测uipicker是否正在旋转。我找到了this to help你。


1
投票

选择代表

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    //selectedRowInPicker is globle NSInteger
    selectedRowInPicker = row;
    yourTextField.text = [NSString stringWithFormat:@"%@",[pickerValueAry objectAtIndex:row]];
}

//完成BtnPress

-(void)doneBtnPressToGetValue
{
    yourTextField.text = [NSString stringWithFormat:@"%@",[pickerValueAry objectAtIndex:selectedRowInPicker]];
}

0
投票

不会。只有在选择器停止时才会获得该值。只有在你得到选择器委托时才会被调用。

© www.soinside.com 2019 - 2024. All rights reserved.