-1

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
    }
}
Lukas Bimba
  • 817
  • 14
  • 35

1 Answers1

1

This is because secondColumnData array contains 8 elements instead of 9 as categories

Shehata Gamal
  • 98,760
  • 8
  • 65
  • 87
  • 1
    damn, im stupid. I looked over those arrays twice and didn't see that lol thank you. Sorry for wasting your guys time – Lukas Bimba Apr 09 '18 at 17:21