我在Swift中的代码出错了。 " NSNumber不是UITextField"的子类型。 我想看看UITextField中的Int是否等于另一个Int。
这是代码。我已将所有代码放入。
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) + 1)
AboveBelow50(Generate)
Number.text = String(Generate)
Input()
}
@IBOutlet weak var PlayerOne: UITextField!
@IBOutlet weak var PlayerTwo: UITextField!
func Input() {
let PlayerOne = self.PlayerOne.text.toInt()
let PlayerTwo = self.PlayerTwo.text.toInt()
}
func Numberequal(Generate: Int) {
if PlayerOne=Generate {
}
}
func AboveBelow50(Generate: Int){
if Generate>=50 {
self.BA50.text = "Above 50"
} else {
self.BA50.text = "Below 50"
}
}
}