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?

6
  • You have to insert one more else condition in cellForRowAtIndexPath method Commented May 3, 2017 at 10:37
  • @Swift_Guru, where bro? if mediapackTableView.isHidden == false {} , this one? Commented May 3, 2017 at 10:41
  • check your code where else part is missing, put there else condition Commented May 3, 2017 at 10:43
  • @Swift_Guru, bro Could you please look at my code again? I modify the code. I still got the problem. :( Commented May 4, 2017 at 3:58
  • again there is no else condition after else if , please put it first. Commented May 4, 2017 at 5:08

1 Answer 1

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?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.