Swift If语句不适用于UILabel

内森·谢弗(Nathan Schafer)

我的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] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

文本字段中的边框和填充样式不适用于swift5

`convertFromSnakeCase`策略不适用于Swift中的自定义`CodingKeys`

RxSwift使用bindTo将Variable <String>绑定到UILabel不适用于Swift 3.0更新

NSForegroundColorAttributeName不适用于UILabel

Google Analytics(分析)不适用于Swift 1.2和Xcode 6.3

数组追加不适用于Swift

UIButton不适用于自定义UITableViewCell(Swift)

Sqlite.swift不适用于Xcode 7.3

NSKeyedUnarchiver不适用于Swift 3

Swift Google Map Marker Tap事件不适用于我

Swift:addGestureRecognizer不适用于StackView子级

蒸气不适用于xcode 9和swift 4

Flickr照片上传不适用于OAtuth1Swift postImage方法

NSNotification不适用于Swift翻译(来自Objective-C)

Swift NSNotification不适用于所有ViewController

Swift dynamicType不适用于泛型函数

滑动手势不适用于侧边栏菜单-Swift

Swift Button.setText不适用于渐变

SwiftChart库不适用于Swift 3.0

removeFromSuperLayer有时不适用于UICollectionViewCell上的子UIView iOS Swift

UICollectionViewFlowLayout minimumLineSpacing不适用于整个集合视图-Swift

indexToScrollTo 不适用于 TableViewCell Swift 中的最后一个 CollectionView

Swift 4 Delegate 不适用于 childViewController

Swift 数组附加不适用于 collectionView 重新加载数据

30 分钟后延迟不适用于 Swift

dosRelativeDateFormatting 不适用于 swift 的未来日期

中缀 % 运算符适用于 Playground,但不适用于包含的 Swift 库

swift coredata 查询不适用于今天的日期

NSPredicate 不适用于 Swift (CoreData)