0
すべてのコンポーネントを再読み込みしても、ピッカービューが何らかの理由で表示されません。私は開始をクリックして、これをロードしたいときにpickerviewをロードしないで、オプションを選択して次の質問に進むことができますか?ピッカービューが表示されない
import UIKit
class QuestionsViewController: UIViewController, UIPickerViewDelegate {
@IBOutlet weak var Next: UIButton!
@IBOutlet weak var pickerview: UIPickerView!
@IBOutlet weak var itemLabel: UILabel!
@IBOutlet weak var label1: UILabel!
@IBOutlet weak var Question: UILabel!
@IBAction func Next(_ sender: Any) {
cQuestion.currentQuestion = cQuestion.currentQuestion + 1
pickerview.reloadAllComponents()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
//var LabelText: String = ""
//var arrayOfQuestions: [String] = ["&","&&","||","None of above"]
//var correctAns:String = ""
//var currentQuestion = 0
let cQuestion = Questions()
//init(arrayOfQuestions:String, correctAns:String, LabelText:String) {
//self.arrayOfQuestions = [arrayOfQuestions]
// self.correctAns = correctAns
// self.LabelText = LabelText
//}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
itemLabel.text = cQuestion.arrayOfQuestions[0]
}
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int{
if(cQuestion.currentQuestion == 0) {
Question.text = "Q1. Which is a logical OR operator"
return cQuestion.arrayOfQuestions.count
} else if (cQuestion.currentQuestion == 1) {
Question.text = "Q2. Compiler generates_file"
return cQuestion.arrayOfQuestions.count
}
hide()
Question.text = "You have finished"
Next.isHidden = true
return cQuestion.arrayOfQuestions.count
}
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String?{
if(cQuestion.currentQuestion == 0) {
return cQuestion.arrayOfQuestions[row]
} else if (cQuestion.currentQuestion == 1) {
return cQuestion.arrayOfQuestions[row]
}
return cQuestion.arrayOfQuestions[row]
}
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int){
if (cQuestion.currentQuestion == 0) {
let itemSelected = cQuestion.arrayOfQuestions[row]
itemLabel.text = itemSelected
} else if (cQuestion.currentQuestion == 1) {
let itemSelected = cQuestion.arrayOfQuestions[row]
itemLabel.text = itemSelected
}
}
func hide() {
pickerview.isHidden = true
itemLabel.isHidden = true
}
}
ピッカービューの作成方法を教えてください。あなたはそれをストーリーボードに設定しましたか?デリゲートリンクをView Controllerに接続するのを忘れましたか?そうしないと、デリゲートメソッドが呼び出されず、ピッカーが空になります。 –
または単に 'pickerView.delegate = self、pickerview.dataSource = self'を使うこともできます –