'UIPickerViewDelegate rowHeightForComponent returns an out of bounds index

I'm writing a code with a UIPickerView that has 3 components. I want each component to have a different row height. I have an array of model components, each has the property rowHeight and I implemented pickerView(_:rowHeightForComponent:) as the following:

func pickerView(_ pickerView: UIPickerView, rowHeightForComponent component: Int) -> CGFloat {
  components[component].rowHeight
}

but it turns out that the parameter component sometimes equals to the number of components, i.e. in my case is sometimes equals 3. So I actually get a component index that is out of bounds. Did anyone have the same problem? Is it a known bug?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source