Swift 4.1
4.1 is a version which i wrote the code. It might be worked in the other version of swift. I'm not sure.
Firstly , right click to the tableViewContent1 and tableViewContent2 and drag it to dataSource and
delegate into View Controller like this image below.
Secondly , you can implement as my code below.
* I've already set the both label in tableViewContent1 and tableViewContent2 with tag = 1000 .
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var tableViewContent1: UITableView!
@IBOutlet weak var tableViewContent2: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
}
}
extension ViewController :
UITableViewDelegate,UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if tableView == tableViewContent1 {
// in order to make the tableViewContent1 get 5 rows.
return 5
}
else{
// in order to make the tableViewContent2 get 3 rows.
return 3
}
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if tableView == self.tableViewContent1 {
let cell = tableView.dequeueReusableCell(withIdentifier: "content1", for: indexPath) as! TableViewCellFirstCustom
let label : UILabel = cell.viewWithTag(1000) as! UILabel{
lab.text = "to change label in content1."
}
return cell
}
else {
let cell = tableView.dequeueReusableCell(withIdentifier: "content2", for: indexPath)
let label : UILabel = cell.viewWithTag(1000) as! UILabel
label.text = "to change label in content2."
return cell
}
}
}
after that you will get result like image below.
It worked for me.