Hey guys, I’m a beginner making my first app and I’m having a major problem with loading my layout in my app.
I have a function which loads a data model struct in my view controller.
func loadUI() {
vocabBox?.text = vocabInfo.returnAllWordDataForN1().0
hiraganaBox?.text = vocabInfo.returnAllWordDataForN1().1
hiraganaBox?.textColor = view.backgroundColor
englishTranslationBox?.text = vocabInfo.returnAllWordDataForN1().2
viewCount?.text = ("View Count: \(vocabInfo.returnAllWordDataForN1().3)")
correctOrIncorrectBox?.text = "Try and Remember!"
correctOrIncorrectBox?.textColor = .white
}
I want to call this function and other similar functions (loadN2(), loadN3() etc) through a tableview controller so when a cell (N1, N2 or N3) is selected it will call the function and load it depending on the cell selected… I created the tableview and did some reading on perform segue and didSelectRowAtIndexPath the function but it just won’t load the data at all. It just comes up with the default storyboard I created with no data populating it.
In my TableViewController I created the data source and delegate methods but when it comes to actually passing the data I’m not sure exactly how to call the correct function and load the data depending on which cell was selected…
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "moveToMainVC" {
if let indexPath = tableView.indexPathForSelectedRow {
let destination = segue.destination as? ViewController
destination?.vocabBox?.text = vocabData.returnAllWordDataForN1().0[indexPath.row]
My GitHub repo is here also so you can get a better idea of what is happening if you’d like to clone it.
I have an idea what is going wrong, in that I’m probably not passing the correct type back in the segue and so it can’t call the function. Also in viewDidLoad in my main view controller, is where the loadUI function is called but as soon as I remove it, I can’t call the function when the corresponding table view is selected.
Any help would be appreciated if it’s not clear I can also explain it in a DM too.