首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Pickerview不显示

Pickerview不显示
EN

Stack Overflow用户
提问于 2016-12-01 04:38:30
回答 1查看 54关注 0票数 0

我的选取器视图由于某种原因无法显示,即使在重新加载所有组件之后也是如此。我点击开始,它只是不加载拾取器视图,因为我希望它加载,然后您可以选择一个选项,并进入下一个问题?

代码语言:javascript
复制
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
} 
}
EN

回答 1

Stack Overflow用户

发布于 2016-12-01 06:00:00

我的猜测是:看起来只要调用numberOfRowsInComponent (它在准备添加到视图时就会这样做),您也会调用hide(),这反过来似乎会将您的pickerView设置为isHidden = true。在您的代码中,我看不到isHidden随后被设置为false的地方。

如果不是这样,还要检查pickerview.dataSource的值是什么,以确保它不是nil。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40897747

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档