gpt4 book ai didi

ios - Pickerview不显示

转载 作者:行者123 更新时间:2023-11-30 12:51:25 28 4
gpt4 key购买 nike

即使在重新加载所有组件后,由于某种原因,我的选取器 View 也没有显示。我单击“开始”,它只是不加载选择器 View ,因为我希望加载它,然后您可以选择一个选项并转到下一个问题?

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
}
}

最佳答案

我的猜测:看起来只要 numberOfRowsInComponent 被调用(它在准备添加到 View 时就会执行),您也会调用 hide() 这似乎又将您的 pickerView 设置为 isHidden = true。我在代码中没有看到 isHidden 随后设置为 false 的任何地方。

如果情况并非如此,还要检查 pickerview.dataSource 的值以确保它不为零。

关于ios - Pickerview不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40897747/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com