How can I access a text field located in a table view cell outside of the cell?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



How can I access a text field located in a table view cell outside of the cell?



After searching around, I couldn't find a solution that worked for me. I have a couple of text fields in a table cell. What I am trying to accomplish is changing those fields from hidden to visible with a leadingSwipe.



Code for cellForRowAt:


cellForRowAt


public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell

let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as UITableViewCell
let newCategory = cell.viewWithTag(5) as! UITextField
let newAmount = cell.viewWithTag(6) as! UITextField
newCategory.isHidden = true
newAmount.isHidden = true



Code for leadingSwipe:


func tableView(_ tableView: UITableView, leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration?
let indexPath = IndexPath(row: 0, section: 0)
let cell = tableView.cellForRow(at: indexPath)
let contextItem = UIContextualAction(style: .normal, title: "Edit") (contextualAction, view, boolValue) in
cell.newCategory.isHidden = false
cell.newAmount.isHidden = false
boolValue(false)

let swipeActions = UISwipeActionsConfiguration(actions: [contextItem])

return swipeActions



I am receiving the error "Value of type 'UITableViewCell?' has no member 'newCategory'" and similar for the newAmount.




1 Answer
1



You need to cast to the appropraite type and declare the properties as outlets


let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! TableCell

cell.////






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard