I've tried all the previous suggestions here for fixing this problem, but still have had no luck. It was working (UIPickerView was correctly populating), but now the app crashes after viewDidLoad() runs. Verified all IBOutlets are correctly connected. Tried re-creating the cocoa touch file.
Here is my view controller code. It's gotta be something minor I'm overlooking. Help!!
class SettingsVC: UIViewController, UIPickerViewDataSource, UIPickerViewDelegate {
@IBOutlet weak var targetCadenceLabel: UILabel?
@IBOutlet weak var cadenceStepper: UIStepper?
@IBOutlet weak var goalPicker: UIPickerView?
var pickerDataSource = ["improve SPM", "maintain SPM"]
override func viewDidLoad() {
super.viewDidLoad()
self.goalPicker?.dataSource = self
self.goalPicker?.delegate = self
//MARK: Setup Tab Bar
let tabBarItem = self.tabBarItem
let incomingSelectedImage: UIImage! = UIImage(named: "settings_icon")?.withRenderingMode(.alwaysOriginal)
tabBarItem?.selectedImage = incomingSelectedImage
tabBarItem?.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor(red: 60/255, green: 159/255, blue: 255/255, alpha: 1.0)], for: UIControlState.selected)
}
//MARK: - Delegates and data sources
//MARK: Data Sources
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return pickerDataSource.count
}
//MARK: Delegates
func pickerView(_ pickerView: UIPickerView, attributedTitleForRow row: Int, forComponent component: Int) -> NSAttributedString? {
let titleData = pickerDataSource[row]
let myFont = UIFont.systemFont(ofSize: 18)
let fontColor = UIColor(red: 60/255, green: 159/255, blue: 255/255, alpha: 1.0)
let myTitle = NSAttributedString(string: titleData, attributes: [NSFontAttributeName: myFont,NSForegroundColorAttributeName:fontColor])
return myTitle
}
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
}
@IBAction func cadenceStepper(_ sender: UIStepper) {
targetCadenceLabel?.text = Int(sender.value).description
}
@IBAction func goPremiumTapped(_ sender: UIButton) {
print("Go Premium Button Tapped")
}
}