【问题标题】:Custom UITableViewCell no member named error Swift自定义 UITableViewCell 没有名为错误 Swift 的成员
【发布时间】:2015-07-04 11:32:58
【问题描述】:

当在 swift 中对UITabelViewCell 进行子类化时,我得到一个错误,即命名的成员不存在

自定义单元格

import UIKit


class CustomRow: UITableViewCell {

    @IBOutlet var namelabel: UILabel!

}

在 tableview 类中访问它

// --- Table view ---

    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

            return data.count

    }

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

           var cell:UITableViewCell = self.tableView.dequeueReusableCellWithIdentifier("CustomRow") as! CustomRow


            cell.namelabel.text = person.valueForKey("engineerName") as? String <-----cant access nameLabel


            return cell
    }

错误:does not have a member named 'name label'

【问题讨论】:

    标签: ios swift uitableview subclassing


    【解决方案1】:

    你忘了一件事

    var cell:CustomRow = self.tableView.dequeueReusableCellWithIdentifier("CustomRow") as! CustomRow
    

    因为CustomRow 应该有nameLabel

    或者直接使用

    var cell = self.tableView.dequeueReusableCellWithIdentifier("CustomRow") as! CustomRow
    

    两者都可以。

    【讨论】:

    • 传奇!谢谢你
    • 会做,我已经投票了,必须等待 12 分钟才能接受 - 你的回答就是这么快
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-31
    • 2015-01-28
    • 2016-06-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多