내 VC에는 UITableView
과 UIlabel
이 있습니다. 내가 코드로 모든 것을했기 때문에 Storyboard
에는 아무것도 없다.UITableView 대리인이 호출되지 않았습니다.
문제 :
나는 어떤
UITableViewDataSource and UITableViewDelegate
가 호출되지 다음UITable
를 다시로드하지 않은 경우.내가 아래 코드에서 수행 한 것처럼
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
"공개"키워드를 제거한 다음 시도하십시오. –
@danypata 멋진 catch –