当在swift中对UITabelViewCell
进行子类时,我得到一个名为的成员不存在的错误
自定义单元格
import UIKit
class CustomRow: UITableViewCell {
@IBOutlet var namelabel: UILabel!
}
在表视图类中访问它
// --- 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'
你忘了一件事
var cell:CustomRow = self.tableView.dequeueReusableCellWithIdentifier("CustomRow") as! CustomRow
因为CustomRow
应该具有nameLabel
或者直接使用
var cell = self.tableView.dequeueReusableCellWithIdentifier("CustomRow") as! CustomRow
两者都会起作用。