Swift如果声明不适用于UILabel

时间:2014-10-13 10:24:01

标签: ios if-statement swift uilabel

我的if语句没有显示我想要的内容。有人可以帮忙吗?我想在UILabel中显示一些文本,这些文本将根据天气随机数低于或高于50来确定。

这是代码。 IF声明即将结束。

import UIKit
import AVFoundation

class ViewController: UIViewController {

var pianoSound = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("two_tone_nav", ofType: "mp3")!)
var audioPlayer = AVAudioPlayer()

override func viewDidLoad() {
    super.viewDidLoad()

    audioPlayer = AVAudioPlayer(contentsOfURL: pianoSound, error: nil)
    audioPlayer.prepareToPlay()
            // Do any additional setup after loading the view, typically from a nib.
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

@IBOutlet weak var Number: UILabel!
@IBOutlet weak var BA50: UILabel!

@IBAction func Generate(sender: AnyObject) {

           audioPlayer.play()

    var Generate = Int(arc4random_uniform(100))
    Number.text = String(Generate)


    func AboveBelow50(){
        if Generate>=50 {
        self.BA50.text = "No"
    }
        else {
    self.BA50.text = "Yes"
    }

    }
}
}

1 个答案:

答案 0 :(得分:0)

放置你的功能:

func AboveBelow50(Generate: Int){
    if Generate>=50 {
        self.BA50.text = "No"
    }  else {
        self.BA50.text = "Yes"
    }

支持你的IBAction,并以这种方式改变它。

并在您的IBAction中打电话:

   var Generate = Int(arc4random_uniform(100))
   AboveBelow50(Generate)