我的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"
}
}
}
}
把你的功能:
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)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句