Wednesday, July 1, 2026
HomeiOS Developmentios - *Swift* Attempting to Hyperlink a variable inside a label to...

ios – *Swift* Attempting to Hyperlink a variable inside a label to a button

[ad_1]

Howdy everybody, I’m a more recent developer and I’m making an attempt to determine navigate to a selected CollectionView primarily based on a randomly generated variable inside a label. I created a button that generates a random climate sample and inside there’s a weatherType variable that’s randomly generated and when the labels weatherType is “Sunny” I need to have the ability to press one other button that can take the person to a SunnyCollectionView.

‘’’ class ViewController: UIViewController {

@IBOutlet weak var firstLabel: UILabel!
@IBOutlet weak var weatherInfoLabel: UILabel!
override func viewDidLoad() {
    tremendous.viewDidLoad()
    // Do any further setup after loading the view.
}

@IBAction func weatherButton(_ sender: Any) {
    let weatherVar = Climate()
    firstLabel.textual content = weatherVar.weatherInfo()
}

@IBAction func clothingCollectionButton() {
    let weatherVar = Climate()
    let storyBoard : UIStoryboard = UIStoryboard(identify: "Major", bundle:nil)

    if weatherVar.randomWeatherType == "Sunny" {
        let nextViewController = storyBoard.instantiateViewController(withIdentifier: "SunCollectionView") as! SunCollectionViewController
        self.current(nextViewController, animated:true, completion:nil)
    }
}’’’

From right here I’m in a position to make use of the weatherButton to get a random climate kind however I wish to use the clothingCollectionButton to take me to the following assortment view primarily based on that climate. May anybody assist! What I’ve up is what I assumed would work however it hasn’t.

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments