Reputation: 5936
When Subclassing a UITabelViewCell
in swift im getting a error that the member named does not exist
Custom Cell
import UIKit
class CustomRow: UITableViewCell {
@IBOutlet var namelabel: UILabel!
}
Accessing it in tableview class
// --- 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
}
Error: does not have a member named 'name label'
Upvotes: 1
Views: 1105
Reputation: 23892
You forgot one thing
var cell:CustomRow = self.tableView.dequeueReusableCellWithIdentifier("CustomRow") as! CustomRow
because CustomRow
should have nameLabel
or use it directly
var cell = self.tableView.dequeueReusableCellWithIdentifier("CustomRow") as! CustomRow
Both will work.
Upvotes: 3