一、UITableView 中调用 UIButton 的 setTitle 会闪swift
滚动列表时比较明显,解决办法: buttonType 改为 custom 便可,可是这样一来 UIButton 的高亮效果也没了,但能够本身手动配置 State Config 网络
2018-02-09 更新,方法二:app
UIView.performWithoutAnimation { self.cancelButton.setTitle(Localized.DIALOG_BUTTON_CANCEL, for: .normal) self.cancelButton.layoutIfNeeded() }
二、监听 UITextField 文本改变iphone
func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool { let text = NSString(string: textField.text!).stringByReplacingCharactersInRange(range, withString: string) }
更好的办法:http://stackoverflow.com/questions/7010547/uitextfield-text-change-eventui
三、模拟较差的网络spa
iPhone 设置 >> Developer >> Network Link Conditioner
code
四、若是支持 iOS 9 多任务分屏,在 iPad 上将没法控横竖屏相关的设置(shouldAutorotate、supportedInterfaceOrientations 都不会回调)orm
https://forums.developer.apple.com/message/13508#13508blog
五、UINavigationController 替换当前 UIViewController ip
extension UINavigationController { func replaceLastViewController(controller: UIViewController) { let stackViewControllers = NSMutableArray(array: self.viewControllers) stackViewControllers.removeLastObject() stackViewControllers.addObject(controller) setViewControllers((stackViewControllers as NSArray) as! [UIViewController], animated: true) } }
若是先 pushViewController 再 removeFromParentViewController 当前 ViewController 返回的 title 会错乱
六、自定义静态 Cell 左右边距对齐的问题
直接加约束设置 15 在 iPad 上显示会有问题,办法: 在 Storyboard/xib 中设置自定义 Cell 和 contentView 的 Preserve Superview Margins 为 true,而后设置 label 的 leadingMargin 为 0 ,注意是要勾选 margin:
七、Swift 3.0 判断泛型类型
if T.self == Class.self {
}