简体   繁体   English

第二个视图上的表视图单元格

[英]Table View Cells on second View

I have a TableView with cells on my first View, and it works well. 我在第一个视图上有一个带有单元格的TableView,它运行良好。 But I want to click on some cell then should appear new View with new Table View & cells. 但是我想单击某个单元格,然后应该出现带有新表视图和单元格的新视图。 But after click, I can see only TableView without any cells. 但是单击后,我只能看到没有任何单元格的TableView。

code of SecondViewController SecondViewController的代码

import UIKit
import WebKit
import Kanna
import Gloss

class SecondViewController: UIViewController, UITableViewDelegate, 
UITableViewDataSource {

@IBOutlet weak var menuTable: SecondViewControllerTableViewCell!


public func tableView(_ tableView: UITableView, 
numberOfRowsInSection section: Int) -> Int {
    return 3
}
public func tableView(_ tableView: UITableView, cellForRowAt 
indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: 
"lte_secondPage", for: indexPath) as! ViewControllerTableViewCell

    return cell
}
override func viewDidLoad() {
    super.viewDidLoad()

}
}

code of FirstViewController FirstViewController的代码

class ViewController: UIViewController, UITableViewDelegate,     
UITableViewDataSource {
let logos = ["ks", "vf", "ls"]
func tableView(_ tableView: UITableView, numberOfRowsInSection 
section: Int) -> Int {
    return logos.count
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: 
IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: 
"lte_firstPage", for: indexPath) as! ViewControllerTableViewCell
   @code@
    }
    return cell
}

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: 
IndexPath) {
    performSegue(withIdentifier: "segue", sender: self)
}


override func viewDidLoad() {
    super.viewDidLoad()

}

Code of First Table Cell Controller 第一表单元格控制器的代码

import UIKit

class ViewControllerTableViewCell: UITableViewCell {
@IBOutlet weak var logoImage: UIImageView!
@IBOutlet weak var regionQuantity: UILabel!
@IBOutlet weak var localityQuantity: UILabel!
@IBOutlet weak var BSQuantity: UILabel!
@IBOutlet weak var updateDate: UILabel!
@IBOutlet weak var namesOfBS: UILabel!


override func awakeFromNib() {
    super.awakeFromNib()
    // Initialization code
}

override func setSelected(_ selected: Bool, animated: Bool) {
    super.setSelected(selected, animated: animated)


}

}

Code of Second Table Cell Controller 第二表单元格控制器代码

 import UIKit

class SecondViewControllerTableViewCell: UITableViewCell {
@IBOutlet weak var label: UILabel!

override func awakeFromNib() {
    super.awakeFromNib()
    // Initialization code
}

override func setSelected(_ selected: Bool, animated: Bool) {
    super.setSelected(selected, animated: animated)

    // Configure the view for the selected state
}

}

And when I tried to print something in public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { print(3) return 3 } it printed nothing and 2019-01-04 22:54:07.057626+0200 BaseStation[12620:273434] <UIView: 0x7f9f52c1e640; frame = (0 0; 375 667); autoresize = W+H; layer = <CALayer: 0x600001a62a80>>'s window is not equal to <BaseStation.SecondViewController: 0x7f9f52c239e0>'s view's window! 当我尝试在public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { print(3) return 3 }打印2019-01-04 22:54:07.057626+0200 BaseStation[12620:273434] <UIView: 0x7f9f52c1e640; frame = (0 0; 375 667); autoresize = W+H; layer = <CALayer: 0x600001a62a80>>'s window is not equal to <BaseStation.SecondViewController: 0x7f9f52c239e0>'s view's window!内容时,它什么也不打印,并且2019-01-04 22:54:07.057626+0200 BaseStation[12620:273434] <UIView: 0x7f9f52c1e640; frame = (0 0; 375 667); autoresize = W+H; layer = <CALayer: 0x600001a62a80>>'s window is not equal to <BaseStation.SecondViewController: 0x7f9f52c239e0>'s view's window! 2019-01-04 22:54:07.057626+0200 BaseStation[12620:273434] <UIView: 0x7f9f52c1e640; frame = (0 0; 375 667); autoresize = W+H; layer = <CALayer: 0x600001a62a80>>'s window is not equal to <BaseStation.SecondViewController: 0x7f9f52c239e0>'s view's window! in debuger apeared after click onto cells in first View 单击第一个视图中的单元格后调试器中的调试器

I think what you are asking is .. When you click on a cell in your tableview, you navigate to a new view controller. 我认为您要问的是..单击表视图中的单元格时,将导航到新的视图控制器。 And this new view controller has a tableview that is not being populated with any cells. 并且此新视图控制器具有一个未填充任何单元格的表视图。

Essentially your question is.. Why is your tableview empty. 本质上,您的问题是..为什么您的表视图为空。

1) Have you checked if you correctly set the table views datasource? 1)您是否检查过是否正确设置了表格视图数据源?

2) Is the datasource empty? 2)数据源是否为空?

3) Does your tableview have a visible height/width? 3)您的表格视图有可见的高度/宽度吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM