gpt4 book ai didi

Swift - 将按钮连接到字符串

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

我有一个从数据库查询填充的 UITextView。

if myDatabase.open(){

var arrayData:[String] = []

let query_lab_test = "SELECT lab_test FROM lab_test ORDER BY lab_test ASC"

let results_lab_test:FMResultSet? = myDatabase.executeQuery(query_lab_test, withArgumentsInArray: nil)

while results_lab_test?.next() == true {

if let resultString = results_lab_test?.stringForColumn("lab_test"){

arrayData.append(resultString)

}
}

let multiLineString = arrayData.joinWithSeparator("\n")

tests_scroller.text = multiLineString
myDatabase.close()
}

如何将使用以下代码创建的复选框按钮加入到 TextView 中的每个字符串行?

let checkButton = UIButton(frame: CGRectMake(300, 500, 20, 20))
checkButton.tintColor=UIColor.blackColor()
checkButton.setBackgroundImage(UIImage(named: "checkbox.png"), forState: UIControlState.Normal)
checkButton.setBackgroundImage(UIImage(named: "checkbox-checked.png"), forState: UIControlState.Selected)
checkButton.addTarget(self, action: "buttonTapAction:", forControlEvents: UIControlEvents.TouchUpInside)
self.view.addSubview(checkButton)

最佳答案

我建议创建 UITableView 而不是 UITextView。然后使用 UILabel(或 UITextView,如果需要编辑)和复选框创建单元格原型(prototype)。

enter image description here

然后使用字符串数组作为数据源

关于Swift - 将按钮连接到字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32752663/

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