gpt4 book ai didi

ios - Pickerview 内容未显示

转载 作者:行者123 更新时间:2023-11-28 15:14:40 25 4
gpt4 key购买 nike

我正在尝试获取其中包含数字列表的选择器 View 。

到目前为止,我可以获得包含所有数字的字符串,但是当将其放入选择器 View 时,选择器 View 始终为空。你能看看我的代码,让我知道哪里出错了吗?

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

最佳答案

从 let pickerString2 = intArray.map 中删除“let” { 字符串($0)

在 viewDidLoad 中,您正在初始化名为 pickerString2 的第二个变量。

let pickerString2 = intArray.map
{
String($0)
}

应该是这样的

pickerString2 = intArray.map
{
String($0)
}

但是您正在尝试用另一个空的 pickerString2 变量填充 pickerview。

var pickerString2 = [String]()

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

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