0
ピッカービューに数字のリストを表示しようとしています。Pickerviewのコンテンツが表示されない
これまでのところ、すべての数値を保持する文字列を取得できますが、ピッカービューに配置するとピッカービューは常に空です。私のコードを見て、どこに間違っているのか教えてください。
import Foundation
import UIKit
class PickerView: UIViewController, UIPickerViewDataSource, UIPickerViewDelegate {
@IBOutlet weak var questionNumberPickers: UIPickerView!
var Category: String!
var numbDict: String!
var QuestionNumber: String!
var cell: UITableViewCell?
var currentTopicIndex = Int()
var setCount = Int()
var setNumber = Int()
var pickerString2 = [String]()
var selectedQuestionNumber: String!
var contacts: NSArray?
var dictContacts = Int()
var pickerArray: NSArray?
@IBOutlet weak var numberOfRow: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
print(currentTopicIndex)
questionNumberPickers.delegate = self
questionNumberPickers.dataSource = self
self.numberOfRow.text = "0"
setCount = Quiz.quizzes[currentTopicIndex].plist.count
let min = 1
let max = setCount
let intArray: [Int] = Array(min...max)
print(intArray)
let pickerString2 = intArray.map
{
String($0)
}
self.questionNumberPickers?.reloadAllComponents()
print(pickerString2)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if(segue.identifier == "questionToQuiz"){
// Get the new view controller using [segue destinationViewController].
let detailScene = segue.destination as! QuizController
detailScene.numberOfQuestions = numberOfRow.text as String!
}
}
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return pickerString2.count
}
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
return pickerString2[row]
}
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
numberOfRow.text = pickerString2[row]
}
}
非常にありがとうEmirC!あなたの命の恩人! – Kailas198