【发布时间】:2017-12-08 13:59:57
【问题描述】:
我在将 view controllers 链接到表视图 cells 时遇到问题。基本上,我的Table View 中有 4 个cells,我希望每个单元格在单击时都指向present 一个单独的view controller。
这是我的快速代码:
import UIKit
var orchard = ["Dog", "Cat", "Bird", "Fish"]
var myIndex = 0
class AnimalList: UITableViewController {
// MARK: - Table view data source
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return orchard.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
cell.textLabel?.text = orchard[indexPath.row]
return cell
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
{
myIndex = indexPath.row
performSegue(withIdentifier: "segue", sender: self)
}
}
这是我的故事板,如您所见,我有 4 个 view controllers 想要连接到 4 个 table view cells。
storyboard
PS:我的table view controller 已经嵌入到navigation controller 中。
我该怎么做?谢谢!
【问题讨论】:
标签: ios iphone xcode uitableview