I am currently working on an app that puts API data into tableview then view the data in a detailsViewController.
My code looks about right to me, and I'm beginning to wonder maybe all the information should be in the tableview for me to pass the data to another controller. Is it possible to pass data to another controller without having to put all the information in the tableview cell?
EDIT: If I were to fetch data in my detailsViewController from the fetchedSpell array, how would I let the detailsViewController know which data to show based on the clicked cell?
I've already tried passing it through but nothing is showing in the details controller when i click on the cell.
Table View Select
func tableView(_ tableView: UITableView, didSelectRowAt indexPath:
IndexPath) {
let storyBoard: UIStoryboard = UIStoryboard(name:"Main",
bundle: nil)
let SpellDetailsViewController =
storyBoard.instantiateViewController(withIdentifier:
"SpellDetailsViewController") as! SpellDetailsViewController
let detail = fetchedSpell[indexPath.row]
SpellDetailsViewController.spellText = detail.spell
SpellDetailsViewController.effectText = detail.effects
SpellDetailsViewController.typeText = detail.types
self.present(SpellDetailsViewController, animated: true,
completion: nil)
}
Spell Details Controller
class SpellDetailsViewController: UIViewController,
UINavigationControllerDelegate {
@IBOutlet weak var spellLabel: UILabel!
@IBOutlet weak var typeLabel: UILabel!
@IBOutlet weak var effectLabel: UILabel!
var spellText: String!
var typeText: String!
var effectText : String!
override func viewDidLoad() {
super.viewDidLoad()
spellLabel.text = spellText
typeLabel.text = typeText
effectLabel.text = effectText
}