0
votes

I'm getting EXC_BAD_INSTRUCTION in my viewDidLoad method with code EXC_I386_INVOP, subcode=0x0, when I'm tying to load delegate to UITableView.

Code looks like:

class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {

  //MARK: PROPERTIES
  @IBOutlet weak var playerTable: UITableView!

  var players = [playerCell]()

  override func viewDidLoad() {
      super.viewDidLoad()
      playerTable.delegate = self
      playerTable.dataSource = self

      players = [
          playerCell(name: "Kogovsek K.", go: 0),
          playerCell(name: "Novak J.", go: 0),
          playerCell(name: "Doe J.", go: 0),
          playerCell(name: "Unknown P.", go: 0),
      ]
  }

  ...

}

I start controller with click on table view item in other controller and view on didSelectRowAtIndexPath

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    let view = ViewController()
    self.presentViewController(view, animated: true, completion: nil)
}
1
You are starting the same controller on didSelectRowAtIndexPath? Is that even feasible?Sohil R. Memon
I'm not starting same controller... I;m starting different controller.klemen676

1 Answers

0
votes

You are directly instantiating ViewController where you should be I archiving from your storyboard (probably be triggering a segue, but you could instantiating with identifier). Because of this your table view doesn't exist (it wasn't unarchived) so you get an exception when trying to use it.