我有嵌入在我的视图控制器的表视图,而且我希望能够设置塞格斯取决于被点击哪些细胞在视图控制器其他四个视图控制器。表视图(内部视图控制器)Segue公司不工作
然而,我似乎无法找出如何控制+从表视图的视图控制器拖动SEGUE。
我相信代码中的相关部分将是:
import UIKit
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
let options = ["Home", "My Account", "Settings", "Support"]
//MARK: Properties
var selectedItem: String?
@IBOutlet weak var nameTextField: UILabel!
@IBOutlet weak var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath as IndexPath)
cell.textLabel?.text = options[indexPath.row]
return cell
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return options.count
}
//MARK: Actions
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if let selectedRow = tableView.cellForRow(at: indexPath){
selectedItem = selectedRow.textLabel?.text
}
if selectedItem == "My Account"{
performSegue(withIdentifier: "classifySegue", sender: self)
} else if selectedItem == "Settings"{
performSegue(withIdentifier: "otherSegue", sender: self)
}
}
}
问题是当前otherSegue来自视图控制器,而不是表视图本身。
https://stackoverflow.com/a/41887007/5461400 –
你的意思是你想从只,而不是从实现代码如下的父视图 - 控制的tableview.view推? – dhin
是的,我只是希望这样做,当我点击表格视图中的一行时,这取决于行中的文本,它将执行特定的继承我指定的视图控制器。 – user3628240