UITableViewCell Accessory Type Checked on Tap & Set other unchecked

后端 未结 9 2294
小蘑菇
小蘑菇 2020-12-03 03:02

I am confused a little bit about settings table view cell accessories.

I have fixed two sections in my table

  • Home
  • Office

What I

9条回答
  •  悲哀的现实
    2020-12-03 03:18

    In Swift 2.0 using custom accessoryView uitableviewcell with swift

    1º Creating Globar var IndexPath

    var indexSelected = NSIndexPath()
    

    2º In didSelectRowAtIndexPath

    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
            indexSelected = indexPath
            TB_Lojas.reloadData()
        }
    

    3º in cellForRowAtIndexPath:

    if SelectedIndexPath == indexPath {
                    let img = UIImageView(frame: CGRect(x: 0, y: 0, width: 20, height: 20))
                    img.image = UIImage(named: "check")
                    cell.accessoryView = img
                }else{
                    let img = UIImageView(frame: CGRect(x: 0, y: 0, width: 20, height: 20))
                    img.image = UIImage(named: "uncheck")
                    cell.accessoryView = img
                }
    }
    

提交回复
热议问题