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



我在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是在xib中添加的UIView。

- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
       cityNameLabel.text = [cityNameArray objectAtIndex:row];
        thePickerView.hidden = YES;
    }

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

 cityNameLabel.text = [cityNameArray objectAtIndex:row];

您在didSelectRow代码中隐藏了picker视图。这可能是问题所在。

- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
   cityNameLabel.text = [cityNameArray objectAtIndex:row];
 //   thePickerView.hidden = YES;
}

comment thePickerView.hidden=是;并检查。

最新更新