Tableview does not update

Asked

Viewed 114 times

0

I am with a tableview with several times, so the user could confirm that consumed the medicine at one of the times in question, until then it is okay, only that I needed to update the tableview after confirmation of the user and remove this time from the list, I tried it this way but without success. Does anyone know how to explain to me why is not updating and a way to be able to update this data

  func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? {
    if indexPath.section == 1{
        let confirmar = UITableViewRowAction(style: .Normal, title: "Já Tomei") { action, index in

            self.confirmaTomouDoseMedicamento((self.arrayNotificacoesAtrasadas[indexPath.row].id))
            self.arrayNotificacoesAtrasadas.removeAtIndex(indexPath.row)
            self.tableView.reloadData()
        }

        confirmar.backgroundColor = UIColor.blueColor()
        return [confirmar]
    }

    return nil
}
func confirmaTomouDoseMedicamento(idNotificacao: Int){
    let appDel: AppDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
    let contexto: NSManagedObjectContext = appDel.managedObjectContext
    NotificacaoDAO().confirmaDosagem(contexto, idNotificacao: idNotificacao)
}
  • Try to put the self.tableView.reloadData() out of the if.

2 answers

0

Replace . Normal by . Destructive in style:

let delete = UITableViewRowAction(style: .Destructive, title: "Delete") { (action, indexPath) in
    self.confirmaTomouDoseMedicamento((self.arrayNotificacoesAtrasadas[indexPath.row].id))
    self.arrayNotificacoesAtrasadas.removeAtIndex(indexPath.row)
    self.tableView.reloadData()
}

0

Hello, I do not know if you have already solved, to update the table view use the reloadData method().

For example:

self.minhatableView.reloadData()

Browser other questions tagged

You are not signed in. Login or sign up in order to post.