gpt4 book ai didi

ios - 在表格 View 中显示数据

转载 作者:行者123 更新时间:2023-12-01 18:37:32 25 4
gpt4 key购买 nike

我创建了两个标签,我想在一个标签中显示问题,并在其他标签中选择答案。
我必须显示带有可选按钮的选项,就像单行中的多项选择题类型一样,一次只能选择一个答案

建议将不胜感激

我在此附上我的代码以及模拟器输出屏幕的屏幕截图。

代码-

class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {


@IBOutlet weak var titleLabel: UILabel!


@IBOutlet weak var topicLabel: UILabel!


var dictionary1:[Int:String] = [0:"Whether you have experienced Pricking-pain, Desquamation,itching or dry skin sensation during seasonal alternate.",
1:"Whether your skin apt to flush( Redness) in hot humid environment ",
2:"Whether your skin has multiple disernible dilated capillaries.",
3:"whether you have once been diagnosed atopic dermatitis or seborrheic dermatitis."]


var dictionary2:[Int:Array<String>] = [0:["Never","Seldom","Usually","Always"],
1:["Never","Seldom","Usually","Always"],
2:["Never","Seldom","Usually","Always"],
3:["Yes", "No"]]

override func viewDidLoad() {
super.viewDidLoad()
titleLabel.text = "Fill Skin Type Survey Form "
titleLabel.textColor = UIColor.black
topicLabel.text = "Are You with sensitive skin type ?"
topicLabel.font = UIFont.boldSystemFont(ofSize: 18)



}



//TableView



func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

return dictionary1.count
}


func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell:TableViewCell = tableView.dequeueReusableCell(withIdentifier: "cell") as! TableViewCell
//cell.questionLabel.text = NSObject.dictionaryWithValues(forKeys: [indexPath.row])

cell.questionLabel.text = dictionary1[indexPath.row]

cell.questionLabel.textColor = UIColor.black
//cell.optionsLabel.text = dictionary2[indexPath.row]

let arr = dictionary2[indexPath.row]

var strr = String()
for str in arr! {
strr = strr + str
}
cell.optionsLabel.text = strr

cell.optionsLabel.textColor = UIColor.black


return cell
}

最佳答案

您必须设置UILabel numberOfLineslineBreakMode属性。

不要忘记添加heightForRowAt方法。

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return dictionary1.count
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell:TableViewCell = tableView.dequeueReusableCell(withIdentifier: "cell") as! TableViewCell

// FOR FIRST DICTIONARY
cell.questionLabel?.numberOfLines = 0
cell.questionLabel?.lineBreakMode = .byWordWrapping

cell.questionLabel?.text = dictionary1[indexPath.row]

// FOR SECOND DICTIONARY
cell.optionsLabel?.numberOfLines = 0
cell.optionsLabel?.lineBreakMode = .byWordWrapping

cell.optionsLabel?.text = dictionary2[indexPath.row]?.joined(separator: "\n")

return cell
}

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}

func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
return 350.0
}

现在看起来像这样。
enter image description here

关于ios - 在表格 View 中显示数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49977065/

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