В моем VC есть один UITableView
и один UIlabel
. Поскольку я сделал все по коду, и в Storyboard
ничего нет.UITableView Делегат не называется
Выпуск:
Если я не перезагружать
UITable
то не любойUITableViewDataSource and UITableViewDelegate
называется.Если я перезаряжаю
UITable
, как я это сделал в моем нижнем коде, тоcellForRow
не вызывается.
Я сделал ниже код работа.
import UIKit
protocol DataVCProtocol
{
func addNewVC(Index : Int)
}
class DataVC: UIViewController, UITableViewDataSource, UITableViewDelegate {
var delegate:DataVCProtocol?
var tblData : UITableView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(true)
self.view.backgroundColor = UIColor.clear
self.tblData = UITableView(frame: CGRect(x: 0, y: 0, width: self.view.frame.size.width - 20 , height: UIScreen.main.bounds.size.height), style: UITableViewStyle.plain)
self.tblData.delegate = self
self.tblData.dataSource = self
self.tblData.register(TblDataCell.self, forCellReuseIdentifier: "dataCell")
self.tblData.showsHorizontalScrollIndicator = false
self.tblData.showsVerticalScrollIndicator = false
self.view.addSubview(self.tblData)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK:- TableView Datasource
// MARK:-
public func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat{
return 60
}
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int{
return 10
}
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell{
let dataCell : TblDataCell = tableView.dequeueReusableCell(withIdentifier: "dataCell") as! TblDataCell
dataCell.lblDataText.text = String("data cell #\(indexPath.row)")
return dataCell
}
public func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath){
delegate?.addNewVC(Index: indexPath.row)
}
}
увидеть правую ячейку
Вы забыли добавить '' 'tableView''' в качестве подсмотра к представлению контроллера. – danypata
Удалите ключевое слово «public», затем попробуйте. –
@ danypata nice catch –