幾天前我剛剛開始學習Swift,並且在遵循教程時遇到了這個問題。 I tried to add the code in text but was having formatting problems so I had to go with an image of the code:(Swift dilema(標題很難想出)
任何幫助,將不勝感激。
這是更正後的代碼。 進口的UIKit
class ViewController: UIViewController {
var currentValue: Int = 0
var targetValue: Int = 0
func startNewRound() {
targetValue = 1 + Int(arc4random_uniform(100))
currentValue = 50
slider.value = Float(currentValue) }
func updateLabels() {
targetLabel.text = "\(targetValue)"
}
@IBOutlet weak var slider: UISlider!
@IBOutlet weak var targetLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
startNewRound()
updateLabels()
// 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.
}
@IBAction func showAlert() {
let alert = UIAlertController(title: "Hello World",
message: "The value of the slider is \(currentValue)"
+ "\nThe target value is: \(targetValue)",
preferredStyle: .alert)
let action = UIAlertAction(title: "Ok", style: .default,
handler: nil)
alert.addAction(action)
present(alert, animated:true , completion: nil)
startNewRound()
updateLabels()
}
@IBAction func sliderMOved(slider: UISlider) {
currentValue = lroundf(slider.value) }
}
你的「startNewRound」方法沒有關閉'}',下面的「updateLabels」在「startNewRound」裏面。注意你如何縮進你的代碼,這不會發生。 – Moritz
編輯你的問題並添加代碼,如果有任何你不知道如何修復的格式問題,其他人可以編輯你的問題來幫助你。順便說一句,歡迎來到StackOverflow。 –
謝謝!這是一個支架問題 – Retsnad