2 Swift 3 在一个视图控制器中的表视图 [英] 2 Table View in One View Controller with Swift 3
问题描述
我在一个视图控制器中有 2 个表视图.我声明这两个表.
I have 2 table views in one View Controller. I declare these two tables.
@IBOutlet weak var packTableView: UITableView!
@IBOutlet weak var mediapackTableView: UITableView!
我在 ViewDidLoad 中声明了这段代码.
I declare this code in ViewDidLoad.
mediapackTableView.delegate = self
mediapackTableView.dataSource = self
mediapackTableView.register(MediaPackTableViewCell.self, forCellReuseIdentifier: "mediaPackCell")
packTableView.delegate = self
packTableView.dataSource = self
并且我还添加了以下代码.
and I also add these following codes.
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if(packSegmentedControl.selectedSegmentIndex != 2)
{
debugPrint("This is NOOOOOOOO")
let cell: TableViewCell1 = tableView.dequeueReusableCell(withIdentifier: "packCell", for: indexPath) as! TableViewCell1
cell.lblId.isHidden = true
SwiftLoading().hideLoading()
returnValues = cell
return returnValues
} //segemented control check
else if packSegmentedControl.selectedSegmentIndex == 2 {
debugPrint("This is YESSSSSSSSSSSS")
packTableView.isHidden = true
mediapackTableView.isHidden = false
self.lblPackDescription.text = NSLocalizedString("Media Packs", comment: "")
let cell: TableViewCell2 = tableView.dequeueReusableCell(withIdentifier: "mediaPackCell", for: indexPath) as! TableViewCell2
cell.textLabel?.text = "SOFTWARE"
debugPrint("HELLO")
return returnValues
}
return returnValues
}
单击第三分段控件"时出现错误.
由于未捕获的异常NSInternalInconsistencyException"而终止应用,原因:无法使用标识符 mediaPackCell 使单元出列 - 必须为标识符注册一个笔尖或类,或连接故事板中的原型单元"
我的参考视频是 https://www.youtube.com/watch?v=MYJRQyAtQYg
有人可以帮我吗?
I got error when I click on Third Segmented Control.
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier mediaPackCell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'
My reference video is https://www.youtube.com/watch?v=MYJRQyAtQYg
Could anyone help me please?
推荐答案
看起来 mediaPackCell 标识的单元有问题.虽然它可能与它相关的一些事情 - 您是否在 UI 上设置了它?
Looks like there's an issue with the cell identified of mediaPackCell. While it could be a few things related to it - did you set it on the UI?
这篇关于2 Swift 3 在一个视图控制器中的表视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!