보기 컨트롤러에 테이블보기가 포함되어 있으며보기 컨트롤러의 셀을 클릭하면 다른보기 컨트롤러 4 개를 설정할 수 있기를 원합니다.표보기 (내부보기 컨트롤러) 작동하지 않는다
그러나 테이블 뷰에서 뷰 컨트롤러로 segue를 + 제어하는 방법을 알아낼 수 없습니다.
나는 코드의 관련 섹션이 될 것이다 믿습니다문제는 현재 otherSegue가보기 컨트롤러 및하지에서 온다 :
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)
}
}
}
이는보기 및 스토리 보드 것 테이블 뷰 자체.
https://stackoverflow.com/a/41887007/5461400 –
당신은 tableview.view에서만 푸시하고 tableview의 부모 viewcontroller에서는 푸시하지 않겠습니까? – dhin
네, 테이블 뷰의 행을 클릭 할 때 행의 텍스트에 따라 지정한 뷰 컨트롤러에 특정 세그먼트를 수행하기 만하면됩니다. – user3628240