gpt4 book ai didi

ios - 如何制作一个按钮来检索最新的信息集?

转载 作者:可可西里 更新时间:2023-11-01 02:17:04 26 4
gpt4 key购买 nike

如何制作一个按钮来检索最新的信息集例如,当我写 Number: 1写完后:2

和:3

和:4

我想要一个按钮来检索我在 Number: 4 之前写的最后一个数字

image

这是我的代码

导入 UIKit

类 View Controller :UIViewController {

var actionString : String?
@IBOutlet weak var textfiled: UITextField!
@IBOutlet var lblzerous: UILabel!
@IBOutlet var lbl: UILabel!
@IBOutlet var button: UIButton!


override func viewDidLoad() {
super.viewDidLoad()


}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

func me() {
lbl.text! = lbl.text! + "\n" + textfiled.text! + "\n" + "----"
lbl.numberOfLines = 0
self.lblzerous.text = String(CInt(self.textfiled.text!)! + CInt(self.lblzerous.text!)!)

}
@IBAction func button(sender: AnyObject) {


if textfiled.text! == "" {


let alertController = UIAlertController(title: "Error", message: " write the number ", preferredStyle: UIAlertControllerStyle.Alert)

let cancelAction = UIAlertAction(title: "ok", style: .Cancel) { (action) -> Void in
self.actionString = "Cancel"


}
alertController.addAction(cancelAction)

self.presentViewController(alertController, animated: true, completion: nil)
return
}
me()

if Int(lblzerous.text!) >= Int("152") {


let alertController = UIAlertController(title: "Gmae Over", message: " ... \(lblzerous.text!)", preferredStyle: UIAlertControllerStyle.Alert)

let cancelAction = UIAlertAction(title: "...", style: .Cancel) { (action) -> Void in
self.actionString = "Cancel"

}
alertController.addAction(cancelAction)

self.presentViewController(alertController, animated: true, completion: nil)

} else {
print("keep going ....!")
}
}

@IBAction func button1(sender: AnyObject) {
// Do SomeCode

}
}

最佳答案

添加一个数组变量作为堆栈,您可以从中恢复更改:

var previousValues: [String] = [String]();
var actionString : String?
@IBOutlet weak var textfiled: UITextField!
@IBOutlet var lblzerous: UILabel!
@IBOutlet var lbl: UILabel!
@IBOutlet var button: UIButton!

然后在 me() 中做:

func me() {
lbl.text! = lbl.text! + "\n" + textfiled.text! + "\n" + "----"
lbl.numberOfLines = 0
self.lblzerous.text = String(CInt(self.textfiled.text!)! + CInt(self.lblzerous.text!)!)
previousValues.append(textField.text ?? "error");

}

编辑:最后在你的撤退按钮中做:

@IBAction func button1(sender: AnyObject) {
if previousValues.count > 0 {
let previousValue = previousValues.removeLast();
lbl.text! = lbl.text! + "\n-" + previousValue + "\n" + "----";
let subtracted = (Int(lblzerous.text!)!) - (Int(previousValue)!);
lblzerous.text = "\(subtracted)"
}
}

Edit2: 为您的标签提供默认值:

override func viewDidLoad() {
super.viewDidLoad()
lblzerous.text = "0";
lbl.text = "0";
}

关于ios - 如何制作一个按钮来检索最新的信息集?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36793428/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com