UIPickerView在iOS8的didSelectRow方法中更新标签时会消失吗?

时间:2014-10-28 11:30:30

标签: ios objective-c ios8

我在UIPickerView iOS 8中遇到了一个问题。当我在didSelectRow方法中选择并从picker更新值到UILabel时,我的pickerView就消失了。这在iOS 7中运行良好。

//在ViewWillAppear中添加选择器

locationPickerView = [[UIPickerView alloc]initWithFrame:CGRectMake(0,0, locationView.frame.size.width, 90)];
    locationPickerView.backgroundColor = [UIColor clearColor];
    locationPickerView.dataSource = self;
    locationPickerView.delegate = self;
    activityIndicatorView.center = locationPickerView.center;
    [locationView addSubview:locationPickerView];

这里的locationView是UIView,它是在xib中添加的。

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

       cityNameLabel.text = [cityNameArray objectAtIndex:row];

        thePickerView.hidden = YES;

    }

如果我评论下面的行选择器没有消失。但我必须更新标签:(

 cityNameLabel.text = [cityNameArray objectAtIndex:row];

1 个答案:

答案 0 :(得分:0)

您正在隐藏didSelectRow代码中的选择器视图。这可能是问题所在。

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

   cityNameLabel.text = [cityNameArray objectAtIndex:row];

 //   thePickerView.hidden = YES;

}

评论thePickerView.hidden = YES;并检查。