2 Table View in One View Controller with Swift 3

不想你离开。 提交于 2019-12-25 09:29:56

问题


I have 2 table views in one View Controller. I declare these two tables.

@IBOutlet weak var packTableView: UITableView!
@IBOutlet weak var mediapackTableView: UITableView!

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
}



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?


回答1:


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?



来源:https://stackoverflow.com/questions/43757311/2-table-view-in-one-view-controller-with-swift-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!