gpt4 book ai didi

ios - Swift,计算数据并将数据插入文本字段

转载 作者:行者123 更新时间:2023-11-29 01:17:20 25 4
gpt4 key购买 nike

我正在尝试制作一个按类(class)按比例分配租金的应用程序,但每当我插入所有数据并按下计算按钮时,它只会在文本框中显示“inf”一词。

代码如下:

   class ViewController: UIViewController {




@IBAction func tapIt(sender: UITapGestureRecognizer) {
monthlyRent.resignFirstResponder()
moveInMonth.resignFirstResponder()
moveInDay.resignFirstResponder()
moveInYear.resignFirstResponder()
billOn.resignFirstResponder()
}

override func viewDidLoad() {
super.viewDidLoad()

}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()


}

var daysInMonth : Int = Int()
var temp : Int = Int()
var daysLivingThere : Int = Int()
var rentPerDay : Double = Double()
var billingDays2 : Int = Int()
var proratedRent : Double = Double()
var addIn = 1
var passingData : String = String()
var dollar = "$"

@IBOutlet var monthlyRent: UITextField!

@IBOutlet var moveInMonth: UITextField!

@IBOutlet var moveInDay: UITextField!

@IBOutlet var moveInYear: UITextField!

@IBOutlet var billOn: UITextField!

@IBOutlet var fieldA: UITextField!


@IBAction func calculate(sender: UIButton) {


let rentMonthly : Double? = Double(monthlyRent.text!)
let dayMoveIn : Int? = Int(moveInDay.text!)
let billingDays : Int? = Int(billOn.text!)
let monthDays : Double? = Double(daysInMonth)


switch moveInMonth
{
case 1, 3, 5, 7, 8, 10, 12:
daysInMonth = 31
case 4, 6, 9, 11:
daysInMonth = 30
case 2:
daysInMonth = 28
default:
break
}


billingDays2 = billingDays! - addIn
temp = daysInMonth - dayMoveIn!
daysLivingThere = temp + billingDays2

rentPerDay = rentMonthly! / monthDays!
let a : Double? = Double(daysLivingThere)
proratedRent = rentPerDay + a!

let b : String? = String(proratedRent)
fieldA.text = dollar + b!


}

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
if (segue.identifier == "btnSubmitSegue") {
let svc = segue.destinationViewController as! SecondViewController;
svc.dataPassed = fieldA.text!
}
}

所有代码都位于一个按钮内。我想将数据从文本框传输到辅助 View Controller ,并且迫切需要文本框正常工作。

最佳答案

可能是因为 monthDays 设置在它所依赖的 daysInMonth 之前,将 let monthDays :... 行移动到 之后code>moveInMonth 开关。

关于ios - Swift,计算数据并将数据插入文本字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35005754/

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