<分区>
抱歉我的英语不好。
我想要这个:当有人点击一个单元格时,它会在另一个 View Controller 中打开。
我以编程方式创建了 TableView 。
import UIKit
class BibleBooksViewController: UIViewController, UITableViewDelegate,
UITableViewDataSource {
private let myArray: NSArray = ["Gênesis", "Êxodo", "Levitico"]
private var myTableView: UITableView!
var bibleArray = BibleBooksMock().booksArray
override func viewDidLoad() {
super.viewDidLoad()
let barHeight: CGFloat =
UIApplication.shared.statusBarFrame.size.height
let displayWidth: CGFloat = self.view.frame.width
let displayHeight: CGFloat = self.view.frame.height
myTableView = UITableView(frame: CGRect(x: 0, y: barHeight, width:
displayWidth, height: displayHeight - barHeight))
myTableView.register(UITableViewCell.self, forCellReuseIdentifier:
"MyCell")
myTableView.dataSource = self
myTableView.delegate = self
self.view.addSubview(myTableView)
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section:
Int) -> Int {
return bibleArray.count
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath:
IndexPath) -> CGFloat {
return 70
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath)
-> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "MyCell", for:
indexPath as IndexPath)
cell.textLabel!.text = "\(bibleArray[indexPath.row].title)"
return cell
}
}
输出是这样的:
iOS版本为12.1 swift版本是4.2