我的代码如下是典型的tableview。我想要做的是有两个tableviews与那里各自的单元格和dx都显示var文本。我尝试使用“返回单元格& & cc”组合东西,但这不起作用。我只是希望能够使用2个不同的tableview中的单元格来在相同的视图控制器中显示相同的变量。在同一视图控制器中使用2个tableviews(swift3)
import UIKit
var text = ["a", "b"]
var row = 0
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet var b: UITableView!
@IBOutlet var a: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if tableView == a {
return 5
}
else {
return 10
}
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if tableView == a {
let cell = UITableViewCell(style: .default, reuseIdentifier: "cell")
return cell
}
else {
let cell = UITableViewCell(style: .default, reuseIdentifier: "dx")
return cell
}
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
row = indexPath.row
}}
我编辑你的建议它建立的代码。但是,任何一个文本视图都不会显示var文本。 –
你的代码建议反映在我上面编辑的问题中。 –