嗨,我正在尝试使用方程式制作一个数学应用程序,我已经学会了如何获取小数键盘,但是当我使用它时,它崩溃并显示有关线程一的消息:
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger. The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in may also be helpful.
2016-02-16 21:13:31.682 Formel bok[586:43971] Can't find keyplane that supports type 8 for keyboard iPhone-PortraitChoco-DecimalPad; using 1022227301_PortraitChoco_iPhone-Simple-Pad_Default
2016-02-16 21:13:34.606 Formel bok[586:43971] Can't find keyplane that supports type 8 for keyboard iPhone-PortraitChoco-DecimalPad; using 1022227301_PortraitChoco_iPhone-Simple-Pad_Default
fatal error: unexpectedly found nil while unwrapping an Optional value (lldb) "
而且:
"Thread 1: EXC_BREAKPOIN(code=1,subcode=0x0002a476c)
我相信它能做到这一点,因为它是 a ,而不是 .点。我尝试将手机设置为美国地区,然后我工作是否有其他解决方案可以使用此代码,我非常感谢收到的任何帮助。
import UIKit
class CylinderViewController: UIViewController {
@IBOutlet weak var radien: UITextField!
@IBOutlet weak var höjden: UITextField!
@IBOutlet weak var svar: UILabel!
@IBOutlet weak var svar2: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
radien.keyboardType = UIKeyboardType.DecimalPad
höjden.keyboardType = UIKeyboardType.DecimalPad
let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: "dismissKeyboard")
view.addGestureRecognizer(tap) // Do any additional setup after loading the view.
}
func dismissKeyboard() {
//Causes the view (or one of its embedded text fields) to resign the first responder status.
view.endEditing(true)
if höjden.text == ""{
}
else{
let atext: Double? = Double(radien.text!) // conversion of string to Int
let btext: Double? = Double(höjden.text!)
let myInt = atext! * atext!
let result = Double(myInt * btext!) * M_PI
svar.text = "\(result)"
let pi = M_PI * 2
let result2 = Float(pi) * Float(atext!) * Float(btext!)
svar2.text = "\(result2)"
}
}
最佳答案
这是您用于本地化的代码。我尝试了美国和瑞典,零问题消失了。
Note: You will need to do the number formatting on your output as well, but this should help you.
import UIKit
class CylinderViewController: UIViewController {
@IBOutlet weak var radien: UITextField!
@IBOutlet weak var höjden: UITextField!
@IBOutlet weak var svar: UILabel!
@IBOutlet weak var svar2: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
radien.keyboardType = UIKeyboardType.DecimalPad
höjden.keyboardType = UIKeyboardType.DecimalPad
let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: "dismissKeyboard")
view.addGestureRecognizer(tap) // Do any additional setup after loading the view.
}
func dismissKeyboard() {
//Causes the view (or one of its embedded text fields) to resign the first responder status.
view.endEditing(true)
if höjden.text == ""{
}
else{
let nf = NSNumberFormatter() // added to use localization
let atext = nf.numberFromString(radien.text!) //added
let btext = nf.numberFromString(höjden.text!) //added
//let atext: Double? = Double(radien.text!) // conversion of string to Int
//let btext: Double? = Double(höjden.text!)
let myInt = Double(atext!) * Double(atext!)
let result = Double(myInt * Double(btext!)) * M_PI
svar.text = "\(result)"
let pi = M_PI * 2
let result2 = Float(pi) * Float(atext!) * Float(btext!)
svar2.text = "\(result2)"
}
}
}
关于xcode - 带小数点的数学应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35439897/