我成功地设置了我的tableView,使其可以根据点击的行正确地传递特定的字符串。然而,我不知道如何检索这些数据。我知道如何在Java中执行此操作,但我对Swift还很陌生,感到困惑。
发送方控制视图:
发送方控制视图:
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.
}
检索 ControlView:
//I want an if else statement here
if senderString == "Stance"{ // <---- correct me if this is wrong
}
else if senderString == "Move Forward"
{
}
IndividualTechniqueController
是什么?它是当前的控制器吗?另外,您只想从cellContent
数组中传递字符串对象吗?还请展示您创建的故事板segue及其标识符。 - Nirav D