0

I currently have a tableview cell that contains a button. Once clicked it calls a function on the main vc and performs a segue. However, since upgrading to iOS 14 it produces an error. It worked great before without issue. I've also tried using dispatch async and it didn't fix the issue.

The new error returned is:

Exception = (NSException *) "*** __boundsFail: index 2 beyond bounds [0..1]"

The code looks like this:

class MainVC: UIViewController, UITableViewDelegate, UITableViewDataSource {

     func showNextVC() {
          performSegue(withIdentifier: "MainVC->NextVC", sender: self)
     }

     func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
          return 1
     }

     func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
          let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! TableviewCell
          cell.vc = self
          return cell
        
    }

}

class TableviewCell: UITableViewCell {

     weak var vc: MainVC?

     @IBAction func touchupinsideButton(_ sender: UIButton) {
        vc?.showNextVC()
    }

}

There are no changes the the tables rows after it is clicked. It's a very simply action. Any ideas?!

  • In general, assigning a reference to a view controller in the cell class like that is a bad pattern. Regardless, you'll need to provide more information. I just gave that a try on iOS 14 simulator, and it runs without error. Try to create a [mre]. – DonMag Sep 17 '20 at 20:04
  • Thanks Don. I'm gonna keep investigating as there's a lot of factors at play in the app. I also use delegates in most cases but in select cases it's been a bit easier to just have a reference to the vc. I always figure out the problem so will post once it's discovered. – Adam Milliken Sep 18 '20 at 02:57

0 Answers0