Swift編碼總結8
阿新 • • 發佈:2018-06-21
eva code nss ade RR oot bus ont share
1.判斷當前控制器是否在顯示:
// 判斷當前控制器是否在顯示 func isCurrentViewControllerVisible() -> Bool { return (self.isViewLoaded) && ((self.view.window != nil)) }
2.解決白屏問題:
其實白屏問題還是控制器的跳轉問題。
if let tempNav = window?.rootViewController as? BaseNavigationController{ for vc in tempNav.childViewControllers.reversed() {if (vc == tempNav.childViewControllers.last && vc.isKind(of: HomeViewController.self)) || (vc == tempNav.childViewControllers.last && vc.isKind(of: SumPayViewController.self)) { break } else if vc.isKind(of: WaiterHomeViewController.self) {if HHTSwitchGlobalData.shared.isBusinessModel { UIApplication.shared.pop2Business() }else { UIApplication.shared.gotoRootViewController() } } } }
3.數據轉模型:
註意數據模型的類型,否則不能正確轉換。
4.NSNumber 與 NSString 轉換精度問題:
https://www.aliyun.com/jiaocheng/400490.html
let formatMoney = String(format: "%.2f", model.money.doubleValue) let dic = ["code":model.code,"id": model.id,"money": formatMoney] as [String : Any]
5.Xib設置UIStackView,註意子控件設置寬度相等,否則造成布局錯亂。
Swift編碼總結8