Swift编码总结8
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,注意子控件设置宽度相等,否则造成布局错乱。
请发表评论