【发布时间】:2017-09-20 04:50:12
【问题描述】:
我下面的代码是一个典型的表格视图。我想做的是有两个表格视图,其中各自的单元格 cell 和 dx 都显示 var 文本。我尝试使用“return cell && cc”组合事物,但这不起作用。我只想能够用来分隔 2 个不同的表视图中的单元格,以在同一个视图控制器中显示相同的变量。
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
}}
【问题讨论】:
标签: ios uitableview swift3 row cell