jeudi 23 mars 2017

How to synchronize generated random number in separate function to another @IBAction func

I have local Json file filled with 2 sets of data: Image and it's Descriprion(text). I am generating random number and on this number, function returns image from Json. Also got a separate UIButton, it creates an alert view where description must be displayed. I can't call same random number in @IBAction func to sync this number, to get description. If theres any kind of solution ill be glad to use it! Thnx a lot. Heres a code:

func popCardViewWithFrame(_ frame : CGRect) -> UIView? {

    let randomIndex = Int(arc4random_uniform(36) + 1)

    let imageView = UIImageView()

    imageView.image = UIImage(named: people[randomIndex].image
    print(randomIndex)
    return imageView

}

heres @IBAction func where i want to use same generated random number:

@IBAction func ButtonAction(_ sender: UIButton) {

    let appearance = SCLAlertView.SCLAppearance(
        kTitleFont: UIFont(name: "HelveticaNeue", size: 20)!,
        kTextFont: UIFont(name: "HelveticaNeue", size: 14)!,
        kButtonFont: UIFont(name: "HelveticaNeue-Bold", size: 14)!,
        showCloseButton: false
    )

    let alert = SCLAlertView(appearance: appearance)

    let subview: UIView = UIView(frame: CGRect(x: 0, y: 0, width: 200, height: 70))
    let x = (subview.frame.width - 180) / 2

    let textfield1 = UILabel(frame: CGRect(x: x, y: 10, width: 180, height: 25))

    textfield1.text = people[randomIndex].text 
    print(randomIndex)

}




Aucun commentaire:

Enregistrer un commentaire