gpt4 book ai didi

swift - 如何将两个 View Controller 链接到以编程方式创建的 TableView ?

转载 作者:行者123 更新时间:2023-11-28 10:35:17 25 4
gpt4 key购买 nike

<分区>

抱歉我的英语不好。

我想要这个:当有人点击一个单元格时,它会在另一个 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
}
}

输出是这样的:

The code output img from the code

iOS版本为12.1swift版本是4.2

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com