Swift編碼總結9

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

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的範圍和精度:code

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

            // 這裏帳單金額過大的時候會形成小數點被抹了 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:blog

該錯誤簡單的說,是因爲 "ViewController" 尚未被加載,就調用該 ViewController 或者 ViewController 內的方法時,就會報這個錯誤。get

 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)
            })
相關文章
相關標籤/搜索