【问题标题】:Table View Cells on second View第二个视图上的表格视图单元格
【发布时间】:2019-01-04 21:00:20
【问题描述】:

我的第一个视图上有一个带有单元格的 TableView,它运行良好。但是我想单击某个单元格,然后应该出现带有新表视图和单元格的新视图。但是点击后,我只能看到没有任何单元格的TableView。

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()

}
}

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()

}

第一个表格单元控制器代码

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)


}

}

第二个表格单元控制器代码

 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
}

}

当我试图打印一些东西时 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! 在第一个视图中单击单元格后,在调试器中出现

【问题讨论】:

    标签: ios swift uitableview view cell


    【解决方案1】:

    我认为您要问的是.. 当您单击表格视图中的单元格时,您会导航到一个新的视图控制器。而且这个新的视图控制器有一个没有填充任何单元格的表格视图。

    基本上你的问题是......为什么你的表格视图是空的。

    1) 您是否检查过您是否正确设置了表格视图数据源?

    2) 数据源是否为空?

    3) 您的 tableview 是否有可见的高度/宽度?​​

    【讨论】:

    • 哦,我真的忘记连接数据源了,但是当我连接它时,现在它打印我。但我发现了新错误let cell = tableView.dequeueReusableCell(withIdentifier: "lte_secondPage", for: indexPath) as! ViewControllerTableViewCell Thread 1: signal SIGABRT。在调试器中Could not cast value of type 'BaseStation.SecondViewControllerTableViewCell' (0x107268fb8) to 'BaseStation.ViewControllerTableViewCell' (0x107269050).
    • 发现错误ViewControllerTableViewCell 应该是SecondViewControllerTableViewCell。谢谢
    猜你喜欢
    • 1970-01-01
    • 2022-01-18
    • 2022-06-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多