ios – I would like delete cell after i tapped on alert motion, however cells deleted earlier than alert controller seem

[ad_1]

I would like delete cell after i tapped on alert motion, however cells deleted earlier than alert controller seem.

 @IBAction func binButton(_ sender: Any) {
        
        let subtitleString = NSAttributedString(string: "Are you certain to delete?", attributes: [
            NSAttributedString.Key.font : UIFont(name: "SFProText-Regular", size: 13) ?? .systemFont(ofSize: 13),
            NSAttributedString.Key.foregroundColor: UIColor.white
        ])
        
        let alert = UIAlertController(title: "Take Consideration", message: "", preferredStyle: .alert)
        alert.setValue(subtitleString, forKey: "attributedMessage")
        alert.view.subviews.first?.subviews.first?.subviews.first?.backgroundColor = UIColor(named: "AlertColor")
        alert.view.tintColor = UIColor.white
        let cancelAlert = UIAlertAction(title: "No", fashion: .default, handler: nil)
        cancelAlert.setValue(UIColor(named: "Orange"), forKey: "titleTextColor")
        
        
        
        let actionDelete = UIAlertAction(title: "Sure", fashion: .default, handler: nil)
        actionDelete.setValue(UIColor(named: "companyTextColor"), forKey: "titleTextColor")
        alert.dismiss(animated: true, completion: nil)
        if let selectedRows = usersTableView.indexPathsForSelectedRows {
            // 1
            var gadgets = [String]()
            for indexPath in selectedRows  {
                gadgets.append(userName[indexPath.row])
            }
            // 2
            for merchandise in gadgets {
                if let index = userName.firstIndex(of: merchandise) {
                    userName.take away(at: index)
                }
            }
            // 3
            usersTableView.beginUpdates()
            usersTableView.deleteRows(at: selectedRows, with: .automated)
            usersTableView.endUpdates()
        }
    
            alert.addAction(cancelAlert)
            alert.addAction(actionDelete)
            self.current(alert, animated: true, completion: nil)
        }

I would like delete cell after i tapped on alert motion, however cells deleted earlier than alert controller seem.

[ad_2]

Leave a Reply

Your email address will not be published. Required fields are marked *