我有 3 个分段控件(游戏名称)和 3 个用于价格、数量、小计的文本字段。我也有 1 个步进器来增加或减少 1 到 5 之间的数量。
当我更改 1 个游戏的数量并更改选择另一个游戏时,我的问题出现了。假设我将 game1 数量增加到 5 并更改游戏。数量字段自动设置为 1。但是步进器中的“+”是不可选择的,当我按步进器中的“-”时,步进器数量变为 4。
当我从分段控制更改游戏时,我需要的是刷新步进值。任何的想法 ?
class ViewController: UIViewController {
@IBOutlet weak var Photo: UIImageView!
@IBOutlet weak var seg_games: UISegmentedControl!
@IBOutlet weak var lbl_motto: UILabel!
@IBOutlet weak var txt_unitPrice: UITextField!
@IBOutlet weak var txt_quantity: UITextField!
@IBOutlet weak var txt_totalPrice: UITextField!
@IBOutlet weak var step_qChooser: UIStepper!
@IBAction func stepChanged(sender: UIStepper) {
if (txt_quantity.text.isEmpty) {
let alert = UIAlertView()
alert.title = "No Game Choose"
alert.message = "Please Pick Your Game First !"
alert.addButtonWithTitle("Ok")
alert.show()
}
else {
txt_quantity.text = Int(sender.value).description
txt_totalPrice.text = TotalCalc()
}
}
func TotalCalc () -> String {
var a = txt_unitPrice.text.toInt()
var b = txt_quantity.text.toInt()
var sonuc = a! * b!
return String(sonuc)
}
@IBAction func seg_games(sender: AnyObject) {
var index = seg_games.selectedSegmentIndex
var choice = seg_games.titleForSegmentAtIndex(index)!
if choice == "Fallout"
{
lbl_motto.text = "Be Prepare your P.I.M.P."
self.Photo.image = UIImage(named: "fallout.png")
txt_quantity.text = "1"
txt_unitPrice.text = "80"
txt_totalPrice.text = TotalCalc()
}
else if choice == "Borderlands"
{
lbl_motto.text = "Ready for BIG BOYS !!!"
self.Photo.image = UIImage(named: "borderlands.png")
txt_quantity.text = "1"
txt_unitPrice.text = "55"
txt_totalPrice.text = TotalCalc()
}
else if choice == "Battlefield"
{
lbl_motto.text = "Choose: Sniper or Assult"
self.Photo.image = UIImage(named: "battlefield.png")
txt_quantity.text = "1"
txt_unitPrice.text = "110"
txt_totalPrice.text = TotalCalc()
}
}