Select multiple rows in tableview and tick the selected ones

前端 未结 5 1676
北海茫月
北海茫月 2020-12-12 17:34

I\'m loading a tableView from a plist file. This works with no problems. I just simply want to \"tick\" the selected rows. At the moment, with my code it didn\'t work as des

5条回答
  •  抹茶落季
    2020-12-12 18:17

    This enable untick.

    class TableViewController: UITableViewController
    {
        var lastSelectedIndexPath = NSIndexPath(forRow: -1, inSection: 0)
    
        override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
        {
            let cell = tableView.dequeueReusableCellWithIdentifier("myCell", forIndexPath: indexPath) 
    
            // Configure the cell...
            cell.textLabel!.text = "row: \(indexPath.row)"
    
            if cell.selected
            {
                cell.selected = false
                if cell.accessoryType == UITableViewCellAccessoryType.None
                {
                    cell.accessoryType = UITableViewCellAccessoryType.Checkmark
                }
                else
                {
                    cell.accessoryType = UITableViewCellAccessoryType.None
                }
            }
    
            return cell
        }
    
        override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)
        {
            let cell = tableView.cellForRowAtIndexPath(indexPath)
    
            if cell!.selected
            {
                cell!.selected = false
                if cell!.accessoryType == UITableViewCellAccessoryType.None
                {
                    cell!.accessoryType = UITableViewCellAccessoryType.Checkmark
                }
                else
                {
                    cell!.accessoryType = UITableViewCellAccessoryType.None
                }
            }
        }
    
        override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
        {
            return 100
        }
    }
    

提交回复
热议问题