2017-03-01 30 views
0

我有一个表格视图,文本字段和更新按钮。表视图单元格数由用户在“文本”字段中的输入确定。表格视图单元格只包含一个文本字段,用户可以在其中输入一些数据。 我想要的是,我想要将表格视图单元格中的用户输入数据存储到数组中,当点击该更新按钮时。这个怎么做?这是最好的方法是什么?如何从动态创建的表格视图单元格的输入字段中检索数据

这是更新按钮中的代码;

@IBAction func onUpdateButtonClick(sender: AnyObject) { 

      let tableViewLength = Int(productNumberTxtField.text!)! // TextField data which decides the table view cell count 

      for index in 0...(tableViewLength-1) 

      { 
       let indexPath = NSIndexPath(forRow: index, inSection: 0) 

       let cell = self.productsTableView.cellForRowAtIndexPath(indexPath) as? ProductCell 

       if(cell!.productTextField.text != "") { // productTextField is the text field in cell 

        UserDataController.sharedInstance.saveToProductsCoreData(userName, productName: (cell!.productTextField.text)!) 

       } 

      } 

     } 
+0

显示乌尔累代码 –

+0

这里我们分享您的代码,如果不保密 – Krunal

+0

@Vishnu Cyruz你尝试一些代码,否则给一些链接到存储阵列中的数据 – iOS

回答

0

声明数组

var setArray : [String] = [] 

第一,同时使文本框的你必须给标签和委托。

textfield.tag = indexPath.row 
textfield.delegete = self 

比文本框的委托方法

func textFieldDidEndEditing(_ textField: UITextField) { 
    if(textField.text != ""){ 
    setArray[textField.tag] = textField.text! as String 
    print(setArray) 
    } 
} 
相关问题