IlludiumPu36
IlludiumPu36

Reputation: 4304

Swift - Join button to strings

I have a UITextView that is populated from a database query.

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()
        }

How can I join a checkbox button created with the code below to each string line in the 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)

Upvotes: 0

Views: 123

Answers (1)

Aleš Kocur
Aleš Kocur

Reputation: 1908

I suggest to create UITableView instead of UITextView. Then create cell prototype with UILabel (or UITextView if editing is necessary) and checkbox.

enter image description here

Then use your array of strings as datasource

Upvotes: 1

Related Questions