0
我想要將我在滑塊值上顯示的數字覆蓋到我的操作事件中單擊此按鈕的位置,並運行搜索提示的數學公式。訪問Swift中的其他函數
滑塊
@IBAction func percentageSlider(sender: UISlider) {
var sliderPercentage = lroundf(sender.value)
sliderValue.text = "\(sliderPercentage)%"
}
按鈕(注意到滑塊百分比計算的話)
@IBAction func calculateTapped(sender: AnyObject) {
//1. get total bill
var userInput = billTextField.text as NSString
var totalBill : Float = userInput.floatValue
//2.Determine the tip value
var tipRate : Float = //HERE SHOULD BE WEHERE THE VALUE FROM THE SLIDER GOES
var indexString : String = "0.\(tipRate)"
var index = indexString.toInt()
//3. Calculate the tip
var tip : Float = totalBill * tipRate
//4. Display the tip
tipLabel.text = "$\(tip)"
}
我怎樣才能得到sliderPercentage顯示爲在按鈕功能的變量?
當我這樣做我得到一個錯誤:( – user278063
什麼樣的錯誤 –
類AppDelegate:NSObject,UIApplicationDelegate {調試器突出顯示此行,並說錯誤代碼「SIGABRT」。它只顯示啓動屏幕,不會超過它 – user278063