I successfully set up my tableview so that it can correctly pass a specific String depending on the row that was tapped. However, I don't know how to retrieve this data. I know how to do it in java but I am new to swift and I find it confusing.
Sender ControlView:
import UIKit
class TechniqueListViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
let cellContent = ["Stance", "Move Forward", "Move Backward", "Move Right", "Move Left", "Jab", "Cross", "Hook", "Uppercut", "Body Jab", "Body Cross", "Body Hook", "Body Uppercut", "Leg Kick", "Body Kick", "Switching Stances", "Switch Leg Kick", "Switch Body Kick", "Push Kick", "Switch Push Kick", "Front Push Kick", "Switch Front Push Kick", "Spinning Back Kick", "Knee", "Switch Knee", "Elbow", "Tornado Kick"]
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int{
//gets # of row
return cellContent.count
}
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell{
//defines content of each cell
let cell = UITableViewCell(style: UITableViewCellStyle.default, reuseIdentifier: "TechniqueCell")
cell.textLabel?.text = cellContent[indexPath.row]
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let cellIndex = indexPath.row
if (cellIndex == 0){
performSegue(withIdentifier: value(forKey: "Stance") as! String, sender: IndividualTechniqueController())
}
else if cellIndex == 1{
performSegue(withIdentifier: "Move Forward", sender: IndividualTechniqueController())
}
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
Retrieving ControlView:
//I want an if else statement here
if senderString == "Stance"{ // <---- correct me if this is wrong
}
else if senderString == "Move Forward"
{
}