我有一个名为LiveMatchVC的ViewController。我想在LiveMatchVC中显示另一个ViewController(名为 LiveMatchMomentsVC ,它有一个 TableView )。
我添加了一个子视图,我在LiveMatchVC中显示了LiveMatchMomentsVC,但我无法在LiveMatchVC中查看LiveMatchMoments的TableView。
我的代码和屏幕截图如下。
我该如何解决这个问题?
White area is my TableView in LiveMatchMomentsVC
LiveMatchVC代码
类LiveMatchVC:UIViewController {
//---------Outlets-----------
@IBOutlet weak var imgLiveMatchScoreBG: UIImageView!
@IBOutlet weak var openLeft: UIBarButtonItem!
let titleCont1 = TZSegmentedControl(sectionTitles: ["Maç Raporu","Canlı Anlatım", "Önemli Olaylar", "İstatistikler", "Kadrolar" ])
override func viewDidLoad() {
super.viewDidLoad()
let liveMatchMomentsVC = storyboard?.instantiateViewController(withIdentifier: "LiveMatchMomentsVC") as! LiveMatchMomentsVC
titleCont1.indexChangeBlock = { (index) in
if self.titleCont1.selectedSegmentIndex == 1 {
self.view.addSubview(liveMatchMomentsVC.view)
liveMatchMomentsVC.view.frame = CGRect(x: 0, y: self.imgLiveMatchScoreBG.frame.height+self.titleCont1.frame.height, width: self.view.frame.width, height: self.view.frame.height-44)
self.addChildViewController(liveMatchMomentsVC)
self.view.addSubview(liveMatchMomentsVC.view)
self.didMove(toParentViewController: self)
}
}
}
}
LiveMatchMomentsVC代码
导入UIKit
类LiveMatchMomentsVC:UIViewController,UITableViewDelegate,UITableViewDataSource {
@IBOutlet weak var tblLiveMatch: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 15
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "MatchEvent", for: indexPath) as! MatchEventTableViewCell
cell.lblMatchEventTime.text = "69"
cell.lblMatchEvent.text = "Goal. Juraj Kucka"
return cell
}
}