0
votes

Comment obtenir indénitation de Textfield qui placée dans la tableView lorsque vous tapez sur le bouton Terminé à l'aide du clavier IQKeyboardManagerSwift à Swift

Je suis nouveau dans Swift et j'utilise IQKeyboardManagerSwiftBabliothèque pour Textfield et TextView. Je ne suis pas capable d'envoyer IndexPath de la TableView à la fonction Sélecteur. Mon code est comme celui-ci

​​TableViewCell P>

 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        guard let cell = tableView.dequeueReusableCell(withIdentifier: "TimeSheetTableViewCell", for: indexPath) as? TimeSheetTableViewCell else {
            return UITableViewCell()
        }
        cell.txtTimeSheet.text = arrcheck[indexPath.row]
        cell.txtTimeSheet.keyboardToolbar.doneBarButton.setTarget(self, action: #selector(doneButtonClicked))
        return cell
    }

 @objc func doneButtonClicked(_ sender: Any) {
        print("Done")
        
    }


0 commentaires

3 Réponses :


0
votes

Commencez d'abord une variable comme celle-ci dans votre application que vous pouvez l'utiliser dans CellForport, Comme ceci: xxx

puis placez ce code dans votre chariotfornorat: xxx

Ce code fonctionnerait si vous n'avez que 1 section dans votre tableView , si vous avez plus de 1, je devrais vous donner un autre code! Après tout, vous pouvez imprimer votre index dans le bouton Action! Amusez-vous

PS: Je viens de vous donner ce que vous avez mis dans votre question, mais je l'utiliserais dans DisSelectrowat au lieu de Cellfrowat si c'était mon projet!


1 commentaires

J'ai besoin d'index sur DonebuttonClicked méthode comme j'utilise Textfield et j'ai besoin d'ajouter des données Textfield dans la matrice.



2
votes

Essayez ce code, cliquez simplement et coller

 set UITextFieldDelegate, UITextViewDelegate 
       
     var strViewFooter = ""
     var textFieldIndexPath = IndexPath() 
     
   func numberOfSections(in tableView: UITableView) -> Int {
        arraycheck.count
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        1
    }
   func textViewDidEndEditing(_ textView: UITextView) {
        strViewFooter = textView.text
    }
    func textFieldDidEndEditing(_ textField: UITextField) {
                    
         let cell: UITableViewCell = textField.superview?.superview as! UITableViewCell
          let table: UITableView = cell.superview as! UITableView
             textFieldIndexPath = table.indexPath(for: cell)!
          }
                    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
         guard let cell = tableView.dequeueReusableCell(withIdentifier: "TimeSheetTableViewCell", for: indexPath) as? TimeSheetTableViewCell else {
              return UITableViewCell()
            }
           cell.txtTimeSheet.keyboardToolbar.doneBarButton.setTarget(self, action: #selector(doneButtonClicked))
            return cell
        }
      
    func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
            let vw = UIView()
            vw.backgroundColor = UIColor.clear
            let titleLabel = UITextView(frame: CGRect(x:10,y: 5 ,width:350,height:150))
            titleLabel.backgroundColor = UIColor.clear
            titleLabel.font = UIFont(name: "Montserrat-Regular", size: 12)
            titleLabel.text  = arrayFootter[section]
            titleLabel.tag = section
            vw.addSubview(titleLabel)
            titleLabel.keyboardToolbar.doneBarButton.setTarget(self, action: #selector(donebuttonClickedOnView))
            return vw
        }
    
         func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
            return 50
        }
              
           @objc func doneButtonClicked(_ sender: Any) {
                 print(textFieldIndexPath)
                 print(textFieldIndexPath.row)
                 print(textFieldIndexPath.section)
                
              }
       @objc func donebuttonClickedOnView(_ sender: UIBarButtonItem){
            arrayFootter.remove(at: sender.tag)
           arrayFootter.insert(strViewFooter, at: sender.tag)
           print(sender.tag)
        }


6 commentaires

Parfait votre code Work Just I Ajouter Cell.txttimesheet.Delegate = Soi dans la méthode de cellules. Merci


@OBJC FUNC DONTBUTTONCLICKED (_ SENDER: TOUT) {IMPRESSION (TEXTFIELDIDEXPATH.ROW])}


Mais je remplace les données du texte du texte, mais il n'imprime que des données anciennes. J'ai besoin de champ de texte actuel.text à DonebuttonClicked


Lorsque vous remplacez les données de Textfield, vous devez en même temps remplacer les données de votre tableau (arachide). comme ça. FUNC TEXTFIEDDIDEDIDEDIDED (_ TEXTFIELD: UITEXTFIELD) {Laisser la cellule: UitailViewCell = TextField.superview? .superview comme! UitailViewCell Laisser la table: UitailView = Cell.Superview comme! Utableview textfieldindexpath = table.indexpath (pour: cellule)! araycheck.remove (à: textfieldindexpath.row) araycheck.insert (textfield.text !, à: textfieldindexpath.row)}


Laissez-nous Continuez cette discussion en chat .


J'ai ajouté TextView à ViewForfooterinsection Comment puis-je faire la même chose. Peux-tu aider s'il te plait!



0
votes

Obtenez IndexPath sur le bouton Click. XXX


0 commentaires