ios
UIPickerView not displaying data in the UIViewController
Could you please look over my code for a UIPickerView? The pickerView shows nothing in the UIViewController but when I print the picker data on the console, it shows the correct data. Outside of viewDidLoad(): var pickerDataSource = Array<String>() Inside my viewDidLoad(): pickeroftheView.delegate = self pickeroftheView.dataSource = self if numberOfMultiPlayers == 2 { pickerDataSource = ["\(multi1Name)", "\(multi2Name)"] }else if numberOfMultiPlayers == 3{ pickerDataSource = ["\(multi1Name)", "\(multi2Name)", "\(multi3Name)"] }else if numberOfMultiPlayers == 4{ pickerDataSource = ["\(multi1Name)", "\(multi2Name)", "\(multi3Name)", "\(multi4Name)"] }else if numberOfMultiPlayers == 5{ pickerDataSource = ["\(multi1Name)", "\(multi2Name)", "\(multi3Name)", "\(multi4Name)", "\(multi5Name)"] }else if numberOfMultiPlayers == 6{ pickerDataSource = ["\(multi1Name)", "\(multi2Name)", "\(multi3Name)", "\(multi4Name)", "\(multi5Name)", "\(multi6Name)"] } print("Data Source: \(pickerDataSource)") } Code: func numberOfComponents(in pickerView: UIPickerView) -> Int { return 1 } func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int { return pickerDataSource.count } func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? { return pickerDataSource[row] } func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) { if row == 0 { giverNumber = 1 } else if row == 1 { giverNumber = 2 } else if row == 2 { giverNumber = 3 } else if row == 3 { giverNumber = 4 } else if row == 4 { giverNumber = 5 } else if row == 5 { giverNumber = 6 } } Thanks in advance!
Related Links
Xamarin MainStoryBoard opening error: Object reference not set to an instance of an object
UIPanGestureRecognizer Fading View after a limit
How to run a function when tableviewcell is selected (for example, update UIImageView when cell is pressed)
Alamofire called twice - Swift
'AppDelegate' does not conform to protocol 'GIDSignInDelegate'
Set color of text in status bar it is not working (swift 3 - iOS 10)
Move the annotation on Google Map like Uber iOS application in Swift?
i want to cache my webview content to load it faster SWIFT3
Swipe to back navigation not working for Localization app
Appium Desktop could not start new session with iOS
Get duration of video with AVFoundation
How do I make my UICollectionView return 3 columns with 1 pixel spacing between them just like instagram? Swift
Failed to obtain a cell from its dataSource - storyboard and code
Core Data Concurrency Debugging
Need help linking mapKit annotation to CollectionView in Swift
Add New data from Bottom in TableView