【发布时间】:2020-10-16 15:35:50
【问题描述】:
我希望我的 swift 代码在第一个 tableview 单元格中放置一个按钮。我的代码使用所有代码,没有情节提要。我不知道在 2 tableview funcs 数据源和委托中放置什么。该按钮不应触发任何操作,该按钮应位于第一个单元格中。
import UIKit
class ViewController: UIViewController,UITableViewDelegate, UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
<#code#>
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
<#code#>
}
var tble = UITableView()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
[tble].forEach{
view.addSubview($0)
$0.translatesAutoresizingMaskIntoConstraints = false
}
tble.dataSource = self
tble.delegate = self
tble.register(UITableViewCell.self, forCellReuseIdentifier: "MyCell")
NSLayoutConstraint.activate([
tble.bottomAnchor.constraint(equalTo: view.bottomAnchor),
tble.leadingAnchor.constraint(equalTo: view.leadingAnchor),
tble.heightAnchor.constraint(equalTo: view.heightAnchor, multiplier: 0.8),
tble.widthAnchor.constraint(equalTo: view.widthAnchor, multiplier: 1),
])
}
}
【问题讨论】:
标签: swift uitableview button delegates