I have a view controller that was originally a single view, but as my app has expanded, it has turned into a tabbed view. I have an array that stores information about horses that gets imported to the TabbedHorseViewer when a button with the horse's name is clicked. The app works fine when it is just one VC, but now it is 5 different VCs connected the code doesn't really know how to handle it.
in the model:
My Horses: This is the VC with a list of horses in the form of buttons
HorseViewController - This is the VC where some of the horse data is shown (there are 4 other VCs controlled by this tabbed view with more info)
When I run the app and try to click on a horse on the list, I get a "Thread 1: signal SIGABRT" error on line 32. The horseViewerSegue is pointing to the tab view controller. The app doesn't crash when I point the segue to the item within the tabbed view controller (the original setup that the code was written for) but in that case the tab bar at the bottom disappears. I want to be able to navigate to the VC and use the tabs, and I want all five tabs to collect different data about the same horse that was clicked in the first VC, fetching data from the array.
Thanks in advance!
in the model:
Code Block var myHorses = [ Horse(name: "Donnerhall", idNumber: 1, gender: "Stallion")
My Horses: This is the VC with a list of horses in the form of buttons
Code Block for horse in myHorses { let button = UIButton() button.addTarget(self, action: #selector(self.lookupHorse(sender:)), for: .touchUpInside) button.setTitleColor(.white, for: UIControl.State.normal) button.setTitle(horse.name, for: UIControl.State.normal) button.backgroundColor = colorLiteral(red: 0.005273803137, green: 0.4785152674, blue: 0.3960535526, alpha: 1) buttonsStack.addArrangedSubview(button) } buttonsStack.translatesAutoresizingMaskIntoConstraints = false } private var horseSelected: Horse? @objc func lookupHorse(sender: UIButton){ let horseName = sender.title(for: .normal) if let theHorse = myHorses.first(where: {$0.name == horseName}) { horseSelected = theHorse self.performSegue(withIdentifier: "horseViewerSegue", sender: self) } } override func prepare(for segue: UIStoryboardSegue, sender: Any?) { switch segue.identifier { case "horseViewerSegue": let horseVC = segue.destination as! HorseViewController horseVC.horsePassed = horseSelected default: print("Unknown segue: \(segue.identifier ?? "nil")") } }
HorseViewController - This is the VC where some of the horse data is shown (there are 4 other VCs controlled by this tabbed view with more info)
Code Block import UIKit class HorseViewController: UIViewController { @IBOutlet weak var horseNameOutlet: UILabel! @IBOutlet weak var horseGenderOutlet: UILabel! var horsePassed: Horse? override func viewDidLoad() { super.viewDidLoad() } override func viewWillAppear(_ animated: Bool) { if let theHorse = horsePassed { horseNameOutlet.text = theHorse.name horseGenderOutlet.text = theHorse.gender } } }
When I run the app and try to click on a horse on the list, I get a "Thread 1: signal SIGABRT" error on line 32. The horseViewerSegue is pointing to the tab view controller. The app doesn't crash when I point the segue to the item within the tabbed view controller (the original setup that the code was written for) but in that case the tab bar at the bottom disappears. I want to be able to navigate to the VC and use the tabs, and I want all five tabs to collect different data about the same horse that was clicked in the first VC, fetching data from the array.
Thanks in advance!