Ios ';UITableViewCell';没有名为'的成员;名称标签'; 我正在使用自定义nib加载到UITableView并尝试访问自定义标签,但似乎无法让它们找到成员!我做错了什么?

Ios ';UITableViewCell';没有名为'的成员;名称标签'; 我正在使用自定义nib加载到UITableView并尝试访问自定义标签,但似乎无法让它们找到成员!我做错了什么?,ios,uitableview,swift,Ios,Uitableview,Swift,更新代码15/4以确保完整性 override func viewDidLoad() { super.viewDidLoad() tableView.rowHeight = 80 // registered the nib var cellNib = UINib(nibName: "IndividualResultCell", bundle: nil) tableView.registerNib(cellNib, forCellReuseIdentifier:

更新代码15/4以确保完整性

override func viewDidLoad() {
    super.viewDidLoad()

    tableView.rowHeight = 80

// registered the nib  
var cellNib = UINib(nibName: "IndividualResultCell", bundle: nil)
tableView.registerNib(cellNib, forCellReuseIdentifier:     
                                          "IndividualResultCell")

    self.monthView = [

    Month(name: "Darren Jensen", salesrev: 15000, gp: 5000,  
          gppercent: 33.3),
    Month(name: "Duncan Lane", salesrev: 17500, gp: 5000, 
          gppercent: 28.6)]

     // Reload the table
    self.tableView.reloadData()
       }

    // downcast the cell to the custom class
  override func tableView(tableView: UITableView, cellForRowAtIndexPath
  indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier
      ("IndividualResultCell", forIndexPath: indexPath) as!
        UITableViewCell

    let month = self.monthView[indexPath.row]

    // Error message here ... nameLabel not a member of UITableViewCell
    cell.nameLabel?.text = month.name
    cell.salesrevLabel?.text = month.salesrev

    return cell
}
----自定义类

import UIKit

  class IndividualResultCell: UITableViewCell {

    @IBOutlet weak var nameLabel: UILabel!
    @IBOutlet weak var salesrevLabel: UILabel!
    @IBOutlet weak var gpLabel: UILabel!
    @IBOutlet weak var gppercentLabel: UILabel!

 }

IndividualResultCell.xib-已检查重用标识符-它是IndividualResultCell

您需要将单元格向下转换到自定义类:

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("IndividualResultCell", forIndexPath: indexPath) as! IndividualResultCell
    ...
}

假设您在InterfaceBuilder中将该类分配给原型单元,或者在代码中正确注册了该类。

您需要将该单元向下转换到自定义类:

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("IndividualResultCell", forIndexPath: indexPath) as! IndividualResultCell
    ...
}

假设您在InterfaceBuilder中将该类分配给原型单元,或者在代码中正确注册了该类。

您需要将该单元向下转换到自定义类:

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("IndividualResultCell", forIndexPath: indexPath) as! IndividualResultCell
    ...
}

假设您在InterfaceBuilder中将该类分配给原型单元,或者在代码中正确注册了该类。

您需要将该单元向下转换到自定义类:

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("IndividualResultCell", forIndexPath: indexPath) as! IndividualResultCell
    ...
}

假设您在InterfaceBuilder中将该类分配给原型单元,或者在代码中正确注册了该类。

首先在viewDidLoad函数中注册NIB

    @IBOutlet var tableView: UITableView
    override func viewDidLoad() {
    super.viewDidLoad()
    self.tableView.registerNib(UINib(nibName: "IndividualResultCell", bundle: nil), forCellReuseIdentifier: "IndividualResultCell")
    }
然后尝试像这样将自定义单元格出列

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("IndividualResultCell", forIndexPath: indexPath) as! IndividualResultCell
编辑1-数组定义 关于您在下面的评论,我假设您已经在代码中定义了类似的东西

class Month  {
var name = String()
var salesrev = Int()
var gp = Int()
var gppercent = Double()
}
然后我会像这样定义数组,看看这是否解决了填充tableview单元格的问题。println命令显示从数组返回意外值的问题

var monthView : Array = []

var theMonth = Month()
theMonth.name = "Darren Jensen"
theMonth.salesrev = 15000
theMonth.gp = 5000
theMonth.gppercent = 33.3

monthView.append(theMonth)

theMonth.name = "Duncan Lane"
theMonth.salesrev = 17500
theMonth.gp = 5000
theMonth.gppercent = 28.6

monthView.append(theMonth)

首先在viewDidLoad函数中注册NIB

    @IBOutlet var tableView: UITableView
    override func viewDidLoad() {
    super.viewDidLoad()
    self.tableView.registerNib(UINib(nibName: "IndividualResultCell", bundle: nil), forCellReuseIdentifier: "IndividualResultCell")
    }
然后尝试像这样将自定义单元格出列

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("IndividualResultCell", forIndexPath: indexPath) as! IndividualResultCell
编辑1-数组定义 关于您在下面的评论,我假设您已经在代码中定义了类似的东西

class Month  {
var name = String()
var salesrev = Int()
var gp = Int()
var gppercent = Double()
}
然后我会像这样定义数组,看看这是否解决了填充tableview单元格的问题。println命令显示从数组返回意外值的问题

var monthView : Array = []

var theMonth = Month()
theMonth.name = "Darren Jensen"
theMonth.salesrev = 15000
theMonth.gp = 5000
theMonth.gppercent = 33.3

monthView.append(theMonth)

theMonth.name = "Duncan Lane"
theMonth.salesrev = 17500
theMonth.gp = 5000
theMonth.gppercent = 28.6

monthView.append(theMonth)

首先在viewDidLoad函数中注册NIB

    @IBOutlet var tableView: UITableView
    override func viewDidLoad() {
    super.viewDidLoad()
    self.tableView.registerNib(UINib(nibName: "IndividualResultCell", bundle: nil), forCellReuseIdentifier: "IndividualResultCell")
    }
然后尝试像这样将自定义单元格出列

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("IndividualResultCell", forIndexPath: indexPath) as! IndividualResultCell
编辑1-数组定义 关于您在下面的评论,我假设您已经在代码中定义了类似的东西

class Month  {
var name = String()
var salesrev = Int()
var gp = Int()
var gppercent = Double()
}
然后我会像这样定义数组,看看这是否解决了填充tableview单元格的问题。println命令显示从数组返回意外值的问题

var monthView : Array = []

var theMonth = Month()
theMonth.name = "Darren Jensen"
theMonth.salesrev = 15000
theMonth.gp = 5000
theMonth.gppercent = 33.3

monthView.append(theMonth)

theMonth.name = "Duncan Lane"
theMonth.salesrev = 17500
theMonth.gp = 5000
theMonth.gppercent = 28.6

monthView.append(theMonth)

首先在viewDidLoad函数中注册NIB

    @IBOutlet var tableView: UITableView
    override func viewDidLoad() {
    super.viewDidLoad()
    self.tableView.registerNib(UINib(nibName: "IndividualResultCell", bundle: nil), forCellReuseIdentifier: "IndividualResultCell")
    }
然后尝试像这样将自定义单元格出列

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("IndividualResultCell", forIndexPath: indexPath) as! IndividualResultCell
编辑1-数组定义 关于您在下面的评论,我假设您已经在代码中定义了类似的东西

class Month  {
var name = String()
var salesrev = Int()
var gp = Int()
var gppercent = Double()
}
然后我会像这样定义数组,看看这是否解决了填充tableview单元格的问题。println命令显示从数组返回意外值的问题

var monthView : Array = []

var theMonth = Month()
theMonth.name = "Darren Jensen"
theMonth.salesrev = 15000
theMonth.gp = 5000
theMonth.gppercent = 33.3

monthView.append(theMonth)

theMonth.name = "Duncan Lane"
theMonth.salesrev = 17500
theMonth.gp = 5000
theMonth.gppercent = 28.6

monthView.append(theMonth)


在为自定义单元格调用registerClass的位置显示代码。在为自定义单元格调用registerClass的位置显示代码。在为自定义单元格调用registerClass的位置显示代码。在为自定义单元格调用registerClass的位置显示代码。仍然卡住。我将interface builder中的原型单元格分配给IndividualResultCell,并认为我已将该单元格向下转换为自定义类。奇怪的是,我有一个类似的应用程序设置,它工作正常。所以您现在得到了错误:“nameLabel不是IndividualResultCell的成员”,对吗?您是否在NIB文件中正确连接了IBOutlet?我想是的。我在IndividualResultCell类中编写了IBOutlet,然后从nib控件中的标签拖动到类中相应的outlet进行连接。连接管理器似乎已链接。在语句“let month=self.monthView[indexPath.row]”之后,使用println语句打印月值:println(“month value\(month)”)这是您期望的字符串形式的月名值吗?添加了println-并获得以下结果。。。月值DailySales.Month应为数组“Month”的成员,例如Darren Jensen。注释掉问题行cell.namelab.text=month.name我确实将nib加载到模拟器中,但仅使用占位符名称。仍然卡住了。我将interface builder中的原型单元格分配给IndividualResultCell,并认为我已将该单元格向下转换为自定义类。奇怪的是,我有一个类似的应用程序设置,它工作正常。所以您现在得到了错误:“nameLabel不是IndividualResultCell的成员”,对吗?您是否在NIB文件中正确连接了IBOutlet?我想是的。我在IndividualResultCell类中编写了IBOutlet,然后从nib控件中的标签拖动到类中相应的outlet进行连接。连接管理器似乎已链接。在语句“let month=self.monthView[indexPath.row]”之后,使用println语句打印月值:println(“month value\(month)”)这是您期望的字符串形式的月名值吗?添加了println-并获得以下结果。。。月值DailySales.Month应为数组“Month”的成员,例如Darren Jensen。注释掉问题行cell.namelab.text=month.name我确实将nib加载到模拟器中,但仅使用占位符名称。仍然卡住了。我将interface builder中的原型单元格分配给IndividualResultCell,并认为我已将该单元格向下转换为自定义类。奇怪的是,我有一个类似的应用程序设置,它工作正常。所以您现在得到了错误:“nameLabel不是IndividualResultCell的成员”,对吗?您是否在NIB文件中正确连接了IBOutlet?我想是的。我在IndividualResultCell类中编写了IBOutlets,然后从nib I co中的标签开始编写