1. 程式人生 > >Swift編碼總結9

Swift編碼總結9

AR true int color hose replace cat tex www.

1.Swift限制textField輸入位數為10位:

func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
        guard let text = textField.text else{
            return true
        }
        let textLength = text.count + string.count - range.length
        
return textLength <= 10 }

2.iOS float與double的範圍和精度:

https://www.jianshu.com/p/ab37c083317b

            // 這裏賬單金額過大的時候會造成小數點被抹了 po bill["billMoney"]! 5978501.1
//            let formatMoney = String(format: "%.2f", (bill["billMoney"] as? Double)!)
//            footPriceLabel.text = String.getSeparatedString(orgStr: String.stringValue(formatMoney, defaultValue: "0"))

3.whose view is not in the window hierarchy:

該錯誤簡單的說,是由於 "ViewController" 還沒有被加載,就調用該 ViewController 或者 ViewController 內的方法時,就會報這個錯誤。

 self.dismiss(animated: false, completion: {
                let vc = PersonAAController()
                vc.personNum = num
//                print((UIApplication.shared.delegate as? AppDelegate)?.window?.rootViewController.self)
                
// whose view is not in the window hierarchy var rootVC = (UIApplication.shared.delegate as? AppDelegate)?.window?.rootViewController while ((rootVC?.presentedViewController) != nil) { rootVC = rootVC?.presentedViewController } rootVC?.popup(controller: vc, direction: .center) })

Swift編碼總結9