2017-03-01 62 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) 
    } 
} 
相關問題