Deselect cell in UitableView

0

I want to cancel which cell was selected. When clicking on the selected cell, it sends the idCategoria to the next view, but when you return it, the cell is still selected and when you want to click on another category it shows those of the previous category

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        tableView.deselectRowAtIndexPath(indexPath, animated: true)
        print(indexPath)

        vcName = values[indexPath.item]["idCategoria"] as! String

        //tableView.deselectRowAtIndexPath(indexPath, animated: true)
        //self.performSegueWithIdentifier("show", sender: indexPath);
        //tableView.reloadData()


    }

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
        if (segue.identifier == "show") {



            if let vc: ViewController = segue.destinationViewController as? ViewController {
                vc.idCategoria = vcName



            }

        }

    }
    
asked by Brandon Josué Cerezo 10.08.2016 в 05:37
source

1 answer

0

In the func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) method, the UITableViewDelegate you must write the following line:

tableView.deselectRowAtIndexPath(indexPath, animated: true)

Finally it would look like this:

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    tableView.deselectRowAtIndexPath(indexPath, animated: true)
}

Check, too, that in the cell you have not put anything by referring to the selection of this. For this you can overwrite the setSelected method of UITableViewCell .

    
answered by 25.04.2017 в 14:10