UIPickerView selection indicator not visible in iOS10

前端 未结 7 2048
刺人心
刺人心 2021-02-04 06:01

I build my project in Xcode 8. UIPickerView separator lines are not visible in iOS 10 simulator and the devices, but works fine on iOS 9.3 devices and simulator. I tried to adju

7条回答
  •  死守一世寂寞
    2021-02-04 06:31

    I had this exact issue when I rebuilt a couple of solutions for iOS10 and deployed to iOS10 on both simulators and devices.

    I narrowed the problem in my case to be down to selecting an item in the picker during initialisation. ie. I populate my picker and if we have already got a selection for this property then I preselect it and the lines are present. I do this during the initialisation when I set up my picker.

    So my fix, which worked in my use case, was to select the 0 element in the case of no existing value.

    Objective-C

    UIPickerView *pickerView;
    
    ...
    
    [pickerView selectRow:0 inComponent:0 animated:YES];
    

    Swift

    let pickerView: UIPickerView
    
    ...
    
    pickerView.selectRow(0, inComponent: 0, animated: true)
    

    This was fine for my solution since I effectively select row zero on setup.

    I haven't had chance to dig into the reasoning or look for a cleaner solution, but since I've solved my problem I thought I'd share it here to help you all out if I can.

提交回复
热议问题