'Trying to link a variable within a label to a button
I’m a newer developer and I’m trying to figure out how to navigate to a specific CollectionView based on a randomly generated variable within a label.
I created a button that generates a random weather pattern and within there is a weatherType variable that’s randomly generated and when the labels weatherType is “Sunny”, “Windy”, “Rainy”, or “Cloud” I want to be able to press another button that will take the user to a SunnyCollectionView, ‘RainCollectionView’,’WindCollectionView’, or ‘CloudCollectionView’.
class ViewController: UIViewController {
@IBOutlet weak var firstLabel: UILabel!
@IBOutlet weak var weatherInfoLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
@IBAction func weatherButton(_ sender: Any) {
let weatherVar = Weather()
firstLabel.text = weatherVar.weatherInfo()
}
@IBAction func clothingCollectionButton() {
let weatherVar = Weather()
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
if weatherVar.randomWeatherType == "Sunny" {
let nextViewController = storyBoard.instantiateViewController(withIdentifier: "SunCollectionView") as! SunCollectionViewController
self.present(nextViewController, animated:true, completion:nil)
}
}
From here, I’m able to use the weatherButton to get a random weather type but I want to use the clothingCollectionButton to take me to the next collection view based on that weather.
When I’m simulating and I hit the clothingCollectionButton, it does not take me to the CollectionView based on the random weatherType within the label.
Could anyone help? What I have up is what I thought would work but it hasn’t.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
