How to add to an array when button is pressed?

寵の児 提交于 2019-12-12 01:23:32

问题


I've got custom buttons on a custom tableview cell, when button is pressed the image changes to checked/unchecked (see code below).

Issues is: How do I add the cell row data thats checked to an array that will be its own table (eg. a table with only checked data).

@IBAction func tickAction(sender: UIButton) {
    println("SSSS")

    if (sender.selected) {
        sender.setImage(UIImage(named:"Unchecked.png"), forState: .Normal)
        sender.selected = false
    }
    else {
        sender.setImage(UIImage(named:"Checked.png"), forState: .Normal)
        sender.selected = true

    }
}

回答1:


A solution would be to extend UITableViewCell into your own class that holds the other data or holds a reference to a model that holds the data.

Ideally, the view controller should hold the models and should get notified by a view that the action took place to act accordingly. The view controller should then add the data to the other array.



来源:https://stackoverflow.com/questions/31335133/how-to-add-to-an-array-when-button-is-pressed

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!