简体   繁体   English

TableView不会在Swift中注册点击,并且自定义单元格不会显示

[英]TableView does not register clicks in Swift & custom cells do not display

I'm trying to use tableViews for the first time but I am running into an issue. 我正在尝试第一次使用tableViews,但是遇到了问题。 When I run my program containing the code below, clicking on a cell is not registered. 当我运行包含以下代码的程序时,单击单元格未注册。 In addition, my custom cells (image below as well) do not display uniquely either. 此外,我的自定义单元格(也如下图所示)也不是唯一显示。 My code: 我的代码:

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 
    print("Success!") 
}

Declaring information: 声明信息:

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    //print(numApplications)
    if numApplications != 0 {

    }
    //print("2nd?")
    //print(numApplications)
    if numApplications < 7 {
        return 7
    }
    else {
        return numApplications
    }
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = UITableViewCell()
    cell.backgroundColor = UIColor.white
    tableView.rowHeight = 85
    cell.textLabel?.text = "\(indexPath.row)"
    //print(indexPath.row)
    //print(applications.count)
    if indexPath.row < applications.count {
        cell.textLabel?.text = applications[indexPath.row].msg
    }
    return cell
}

我的手机

运行时的单元格

Replace this 取代这个

let cell = UITableViewCell()

with

let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as! CellName

Where CellName is your class that you set for the prototype cell in IB with identifier cell 其中CellName是您为IB中具有标识符cell的原型单元设置的类

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

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