2015-02-10 62 views
0

enter image description here错误在swift中添加两个表格视图

我使用两个tableviews显示数据。我的编码如下。我收到这样的错误[图片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 
    } 

} 

回答

0

错误表明铸造操作as失败。

仔细检查你的故事板,并确保这些细胞的类别和标识的设置是否正确:

  • 法律表应包含与标识符“法律”的单元和类“laws_TblVwCell”
  • 国家表应包含与标识符“国家”的单元和类“country_TblVwCell”

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

+0

嗨大卫.. !!但是当我们加载一个表时,两个表格正在工作。但是,当我们加载两个,我得到这个错误。 – 2015-02-10 17:22:08

+0

那么不知道,我所知道的只是错误消息所说的和一个非常不完整的代码示例。检查堆栈跟踪并查看是否可以确切地确定哪个转换失败,但给定代码中只有2个选项。 – 2015-02-10 17:25:18

+0

当然我会仔细检查..!还有一件事,你可以检查一下并解释我。 http://stackoverflow.com/questions/28325384/in-swift-dynamic-height-for-uitextview-in-uicollectionview – 2015-02-10 17:29:20

相关问题