[英]Perform Segue from UITableViewController to UIViewController with Array Value Swift3
我正在努力掌握话题,并已创建了简单的视图控制器,第一个是使用以下类的简单TableViewController
import UIKit
class CourseTVC: UITableViewController {
var courseVenue = ["Cardiff", "Swansea", "Rhyl", "Bangor"]
var courseDate = ["27th February 2017", "9th March 2017", "17th March 2017", "23rd March 2017"]
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return courseVenue.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "courseCell", for: indexPath)
cell.textLabel?.text = courseVenue[indexPath.row]
cell.detailTextLabel?.text = courseDate[indexPath.row]
return cell
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "showMapDeail" {
let destinationController = segue.destination as! CourseMapVC
if let indexPath = tableView.indexPathForSelectedRow {
destinationController.courseTitle = courseVenue[indexPath.row]
}
}
}
}
我正在使用简单的脚本数组来填充单元格数据。 这很好用,我想将选定的行标题传递给第二个ViewController并仅显示场地标题。 第二个视图控制器打开(该情节在情节提要上被命名为showMapDetail,并且是一个显示情节),但不显示场地标题。 因此,第二个视图控制器的类为
import UIKit
class CourseMapVC: UIViewController {
@IBOutlet weak var venueTitle: UILabel!
var courseTitle: String = ""
override func viewDidLoad() {
super.viewDidLoad()
venueTitle.text = courseTitle
}
}
没有错误,也没有传递数据或传递nil值。 似乎有线索可以进一步询问,因此任何指针都可以收到。
谢谢。
抱歉,我发布此消息后,立即注意到segue标识符中有错字。
不管怎么说,多谢拉。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.