Uitableview error

Asked

Viewed 51 times

0

Gentlemen, are you all right? I’m having difficulties with Uitableview and Uitableviewcell, when I try to pass information from a selected Uitableviewcell to another screen is giving me this error

'NSInternalInconsistencyException', reason: '-[UITableViewController 
loadView] instantiated view controller with identifier 
"WorldCupViewController" from storyboard "Main", but didn't get a 
UITableView.'

Fistviewcontroller

class FistTableViewController: UITableViewController {

var infosCups: [WordCop] = []
override func viewDidLoad() {
    super.viewDidLoad()
    loadWordCups()
    // Uncomment the following line to preserve selection between 
    presentations

}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    let vc =  segue.destination as! WorldCupViewController
    let worldCup = worldCups[tableView.indexPathForSelectedRow!.row]
    vc.worldCupTeste = worldCup
}

func loadWordCups(){
    let fileURL = Bundle.main.url(forResource: "winners.json", withExtension: nil)!
    let jsonData = try! Data(contentsOf: fileURL)
    do {
        worldCups = try JSONDecoder().decode([WordCop].self, from: jsonData)
    }catch{
        print(error.localizedDescription)
    }
}
// MARK: - Table view data source

override func numberOfSections(in tableView: UITableView) -> Int {
    // #warning Incomplete implementation, return the number of sections
    return 1
}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    // #warning Incomplete implementation, return the number of rows
    return worldCups.count
}


override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! WorldCupTableViewCell

    // Configure the cell...
    let worldCup = worldCups[indexPath.row]
    cell.prepare(with: worldCup)
    return cell
}
}

Segundtableviewcontroller

class WorldCupViewController: UITableViewController{


var worldCupTeste: WordCop!

override func viewDidLoad() {
    super.viewDidLoad()
    print(worldCupTeste.country)


}

// MARK: - Table view data source

override func numberOfSections(in tableView: UITableView) -> Int {
    // #warning Incomplete implementation, return the number of sections
    return 1
}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    // #warning Incomplete implementation, return the number of rows
    return 1
}

}

Tableviewcell

class WorldCupTableViewCell: UITableViewCell {

@IBOutlet weak var lbYear: UILabel!
@IBOutlet weak var ivWinner: UIImageView!
@IBOutlet weak var ivVice: UIImageView!
@IBOutlet weak var lbWinner: UILabel!
@IBOutlet weak var lbVice: UILabel!
@IBOutlet weak var lbWinnerScore: UILabel!
@IBOutlet weak var lbViceScore: UILabel!
@IBOutlet weak var lbCountry: UILabel!



override func awakeFromNib() {
    super.awakeFromNib()
    // Initialization code
}

override func setSelected(_ selected: Bool, animated: Bool) {
    super.setSelected(selected, animated: animated)

    // Configure the view for the selected state
}
func prepare(with cup: WordCop ){
    lbYear.text = "\(cup.year)"
    ivWinner.image = UIImage(named: cup.winner)
    ivVice.image = UIImage(named: cup.vice)
    lbWinner.text = String(cup.winner)
    lbVice.text = cup.vice
    lbWinnerScore.text = cup.winnerScore
    lbViceScore.text = cup.viceScore
    lbCountry.text = cup.country
}

}

Where can I be missing?

Edit: I found the error :

In the Segundtableviewcontroller exchange that:

 class WorldCupViewController: UITableViewController

for that:

class WorldCupViewController: UIViewController
  • 1

    Your tableview is the first thing to appear on the screen?

  • The tableViewCell yes

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.