PickerViewに血液型を表示しようとしていますが、何らかの理由で選択肢が疑問符としてしか表示されません!UIPickerViewの疑問符の表示
は、ここに私のコードです:
class RegisterViewController: UIViewController, UIPickerViewDataSource, UIPickerViewDelegate {
//Methods for PickerViewDataSource
@available(iOS 2.0, *)
public 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]
}
@IBOutlet weak var selectedDate: UILabel!
@IBOutlet weak var birthDatePicker: UIDatePicker!
@IBOutlet weak var mobileNumberField: UITextField!
@IBOutlet weak var emailField: UITextField!
@IBOutlet weak var nameField: UITextField!
@IBOutlet weak var bloodTypePicker: UIPickerView!
@IBOutlet weak var selectedType: UILabel!
let pickerDataSource = ["Group A", "Group B", "Group AB", "Group O"];
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
super.viewDidLoad()
self.bloodTypePicker.dataSource = self;
self.bloodTypePicker.delegate = self;
}
func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int)
{
if(row == 0)
{
self.selectedType.text = "Group A"
}
else if(row == 1)
{
self.selectedType.text = "Group B"
}
else if(row == 2)
{
self.selectedType.text = "Group AB"
}
else
{
self.selectedType.text = "Group O"
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func datePickerAction(_ sender: Any) {
var dateFormatter = DateFormatter()
dateFormatter.dateFormat = "dd-MM-yyyy"
var strDate = dateFormatter.string(from: birthDatePicker.date)
self.selectedDate.text = strDate
}
}
とここに表示されているもののスクリーンショットです:事前にhttp://sourcefreeze.com/ios-uipickerview-example-using-swift/
ありがとう:
私はこのチュートリアル以下ました。