在swift中添加两个表视图时出错

时间:2015-02-10 14:42:11

标签: uitableview swift ios8

enter image description here

我使用两个tableviews来显示数据。我的编码如下。我收到了这样的错误[image 1]。我不知道如何解决这个问题。请帮助我。如果我用1表测试它工作正常。但是,在使用两个表时,这种类型的错误即将到来。另外,为什么我收到此错误。请检查我的代码。

override func viewDidLoad() {
        super.viewDidLoad()

        self.country_table_view.registerClass(UITableViewCell.self, forCellReuseIdentifier: "countries")
        self.laws_table_view.registerClass(UITableViewCell.self, forCellReuseIdentifier: "laws")

        self.country_table_view.rowHeight = 60
        self.laws_table_view.rowHeight = 60

    }



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

    if(tableView == country_table_view)
    {
        return self.countries.count
    }
    else
    {
        return self.laws_title.count
    }

}


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

    if(tableView == laws_table_view)
    {

        var cell_new = tableView.dequeueReusableCellWithIdentifier("laws", forIndexPath: indexPath) as laws_TblVwCell

        cell_new.laws_label.text = laws_title[indexPath.row]


        return cell_new

    }

    else
    {            
        var cell = tableView.dequeueReusableCellWithIdentifier("countries", forIndexPath: indexPath) as country_TblVwCell

        cell.country_name_label.text = self.countries[indexPath.row]


        return cell
    }

 }

1 个答案:

答案 0 :(得分:0)

错误表示投射操作as失败。

仔细检查您的故事板并确保正确设置了单元格的类和标识符:

  • 法律表应包含一个带有标识符"法律"和班级" laws_TblVwCell"
  • 国家/地区表应包含一个标识符为“#34;国家/地区”的单元格。和班级" country_TblVwCell"

而且,fwiw,为了易读性,这两个课程都应该重命名为至少以大写字母开头。类,结构,枚举和其他数据类型名称应始终以大写字母开头。变量(和字段)应始终以小写字母开头。