Search code examples
iosswiftuitableviewanimationuipopovercontroller

How to disable animation in TableView selection in Popover?


I have a popover that appears when I click on a cell. In this popover, there is a TableView with a row. When I click on that row, there is three new rows that appears with an animation. I would like to remove that animation. Is it possible ?

Here is my code :

extension PlanningActionTableViewController
{
    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
    {
        return numberOfRows()
    }

    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
    {
        let cell = tableView.dequeueReusableCellWithIdentifier("ActionCell", forIndexPath: indexPath) as!PlanningActionCell


        // Info cells
        if registration == nil
        {
            if slot.registrations.count > indexPath.row
            {
                let contact = slot.registrations[indexPath.row].contact
                let name = contact.lastname + " " + contact.firstname
                cell.actionLabel.text = (name.characters.count > 1 ? name : "Réservation en cours")
                cell.accessoryType = .DisclosureIndicator
                cell.imageSymbol.image = UIImage(named: "picto.user.default")

                return cell
            }

            cell.actionLabel.text = "Ajouter"
            cell.accessoryType = .None
            cell.imageSymbol.image = UIImage(named: "picto.user.add")

            return cell

        }

        // Actions cell
        switch indexPath.row
        {
        case 0:
            cell.actionLabel.text = "Détails"
            cell.accessoryType = .None
            cell.imageSymbol.image = UIImage(named: "picto.user.details")

        case 1:
            var state = "Non"
            if let contact = registration?.contact
            {
                state = (contact.isArrived ? "Oui" : "Non")
            }

            cell.actionLabel.text = "Est arrivé: " + state
            cell.accessoryType = .None
            cell.imageSymbol.image = UIImage(named: "picto.user.valid")

        default:
            cell.actionLabel.text = "Supprimer booking"
            cell.actionLabel.textColor = UIColor.redColor()
            cell.imageSymbol.image = UIImage(named: "picto.user.delete")
            cell.accessoryType = .None
        }

        return cell
    }
}

NumberOfRows :

func numberOfRows() -> Int
{
    if registration == nil
    {
        return slot.subslotsCount
    }

    return 3
}

Example in video :

<iframe src="//gifs.com/embed/1wvE6R" frameborder="0" scrolling="no" width='480' height='220.7665505226481' style="-webkit-backface-visibility: hidden;-webkit-transform: scale(1);" ></iframe>


Solution

  • In your viewDidLoad, set animations to false:

    UIView.setAnimationsEnabled(false)