This is weird because I have two columns of data where the first column dictates what the second column will show when selected. Once I reach the last string in the first column then it will throw a fatal error, otherwise it works as it should. When I reach "Transportation" the error is thrown. The error get thrown on "numberOfRowsInComponent" - "return secondColumnData[selected].count".
var categories = ["Attractions & Entertainment", "Eating & Drinking", "Financial Institution", "Lodging Establishment", "Medical & Health", "Public Services & Buildings", "Service", "Stores & Shopping", "Transportation"]
var transportation = ["Car Rental Agency", "Driving School", "Gas Station", "Parking Garage", "Parking Lot", "Taxi Service", "Transportation Service", "Truck Rental Agency"]
var secondColumnData: [[String]] = []
override func viewDidLoad() {
super.viewDidLoad()
pickerView.delegate = self
pickerView.dataSource = self
pickerView.setValue(UIColor.white, forKey: "textColor")
secondColumnData = [attrationsAndEntertainment, eatingAndDrinking, financialInstitution, lodgingEstablishment, medicalAndHealth, service, storesAndShopping, transportation]
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
picker.delegate = self
}
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 2
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
if component == 0 {
return categories.count
} else {
let selected = pickerView.selectedRow(inComponent: 0)
return secondColumnData[selected].count
}
}