I have set up a button on the tableview cell and I am wondering how I can manipulate it. Namely, I am interested in changing the name title of the button and add another target (different capabilities of the button) to when the button is clicked. My thinking is that this needs to be added into the buttonClicked func, but I am not sure how to reference the specific cellForRow that was clicked. Perhaps a conditional can be used to in cellForRow that determines what the button title is? I am not too sure what the best way to go about this is.
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = guestTableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
let button : UIButton = UIButton(type:UIButtonType.custom) as UIButton
button.frame = CGRect(origin: CGPoint(x: 200,y :60), size: CGSize(width: 100, height: 24))
let cellHeight: CGFloat = 44.0
button.center = CGPoint(x: view.bounds.width / (4/3), y: cellHeight / 2.0)
button.setTitleColor(.blue, for: .normal)
button.addTarget(self, action: #selector(buttonClicked), for: UIControlEvents.touchUpInside)
button.setTitle("Add", for: UIControlState.normal)
cell.addSubview(button)
return cell
}
func buttonClicked(sender : UIButton!) {
print("Added!")
}