swift 2.0项目开发总结一(开发常用)
一:新特性(版本判断)的实现
1 let versionStr = "CFBundleShortVersionString" 2 let cureentVersion = NSBundle.mainBundle().infoDictionary![versionStr] as! String 3 let oldVersion = (NSUserDefaults.standardUserDefaults().objectForKey(versionStr) as? String) ?? "" 4 5 if cureentVersion.compare(oldVersion) == NSComparisonResult.OrderedDescending { 6 NSUserDefaults.standardUserDefaults().setObject(cureentVersion, forKey: versionStr) 7 NSUserDefaults.standardUserDefaults().synchronize() 8 return LeadpageViewController() 9 } 10
二:重写导航栏的push方法,实现左右按钮的统一和个性化
1 if self.childViewControllers.count > 0 { 2 let vc = self.childViewControllers[0] 3 4 if self.childViewControllers.count == 1 { 5 backBtn.setTitle(vc.tabBarItem.title!, forState: .Normal) 6 } else { 7 backBtn.setTitle("返回", forState: .Normal) 8 } 9 10 viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(customView: backBtn) 11 viewController.hidesBottomBarWhenPushed = true 12 } 13 14 super.pushViewController(viewController, animated: animated) 15 16
三:iOS8中新的计算cell高度的方法结合Xib中底部约束
1 // 估算cell的高度 2 tableV.estimatedRowHeight = 200 3 // 设置tableView的自动布局样式 4 tableV.rowHeight = UITableViewAutomaticDimension
时间: 2024-10-20 04:35:57