加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Swift编码总结9

发布时间:2020-12-14 05:12:14 所属栏目:百科 来源:网络整理
导读: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.coun

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)
            })

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读