I have a custom tableView cell with a UILabel and a UITextField. I would like to append the data from the textField with label to an array of dictionaries ([label:textfield]). I can get the textField data using textFieldDidEndEditing but I am not sure how to get the cell label for that same textfield. I would think I would need access to that cell's indexPath. I tried sending a notification to DidSelectRow but that seemed too complicated.
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: expenseCell, for: indexPath) as! LineItemTableViewCell
let sectionsArray = expenses[sections[indexPath.section]]
let expenseItem = sectionsArray?[indexPath.row]
cell.budgetLineItemView.label.text = expenseItem!
cell.budgetLineItemView.lineItemTextField.delegate = self
return cell
}
//MARK: UITextField Delegate
func textFieldDidBeginEditing(_ textField: UITextField) {
textField.layer.borderColor = UIColor.blue.cgColor
textField.keyboardType = .decimalPad
textField.becomeFirstResponder()
}
func textFieldDidEndEditing(_ textField: UITextField) {
//get textfield text after editing here
}
This is my dictionary:
var expenses:[String:[[String:Double]]] = ["Housing":[["Rent/Mortgage":0.0],
["Gas":0.0],["Water/Power":0.0],["Cable/Internet":0.0],["Garbage":0.0],["Property
Tax":0.0],["Homeowners/Renters Insurance":0.0]],"Transportation":[["Car
Payment":0.0],["Car Insurance":0.0],["Roadside Insurance":0.0]],"Other Expenses":
[["Health Insurance":0.0],["Life Insurance":0.0],["Disability Insurance":0.0],
["Student Loans":0.0],["Cell Phone":0.0],["Other":0.0]]]
for cell in tableView.visibleCells() as! [UITableViewCell] { //do something with the cell here.}- iphonicNSArray or, NSDictionaryyou need to useNSMutableArray or, NSMutableDictionaryand after changing the values reload the table. - iphonic