2 Table View in One View Controller with Swift 3
Asked Answered
Q

1

0

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?

Quixote answered 3/5, 2017 at 10:19 Comment(6)
You have to insert one more else condition in cellForRowAtIndexPath methodMasterwork
@Swift_Guru, where bro? if mediapackTableView.isHidden == false {} , this one?Quixote
check your code where else part is missing, put there else conditionMasterwork
@Swift_Guru, bro Could you please look at my code again? I modify the code. I still got the problem. :(Quixote
again there is no else condition after else if , please put it first.Masterwork
btw what are you going to do, what is the functionality?Masterwork
L
0

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?

Lubricity answered 4/5, 2017 at 4:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.