zoukankan      html  css  js  c++  java
  • 【Swift 2.2】iOS开发笔记(三)

      1、UITableView 中调用 UIButton 的 setTitle 会闪

        滚动列表时比较明显,解决办法: buttonType 改成 custom 即可,但是这样一来 UIButton 的高亮效果也没了,但可以自己手动配置 State Config 

        2018-02-09 更新,方法二:

            UIView.performWithoutAnimation {
                self.cancelButton.setTitle(Localized.DIALOG_BUTTON_CANCEL, for: .normal)
                self.cancelButton.layoutIfNeeded()
            }

      2、监听 UITextField 文本改变

        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-event

      3、模拟较差的网络

        iPhone 设置  >>  Developer  >>  Network Link Conditioner

         

      4、如果支持 iOS 9 多任务分屏,在 iPad 上将无法控横竖屏相关的设置(shouldAutorotate、supportedInterfaceOrientations 都不会回调)

        https://forums.developer.apple.com/message/13508#13508

      5、UINavigationController 替换当前 UIViewController 

    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 会错乱

      6、自定义静态 Cell 左右边距对齐的问题

        直接加约束设置 15 在 iPad 上显示会有问题,办法: 在 Storyboard/xib 中设置自定义 Cell 和 contentView 的 Preserve Superview Margins 为 true,然后设置 label 的 leadingMargin 为 0 ,注意是要勾选 margin:

        http://stackoverflow.com/questions/27420888/uitableviewcell-with-autolayout-left-margin-different-on-iphone-and-ipad

      7、Swift 3.0 判断泛型类型

        if T.self == Class.self {

               }

  • 相关阅读:
    java中 == 与equals 的区别
    java中的多线程 // 基础
    MySQL-锁机制
    将博客搬至CSDN
    MySQL-事务
    MySQL-存储过程
    MySQL-触发器
    MySQL-视图
    Redis设置Auth认证保护
    PHP目前常见的五大运行模式
  • 原文地址:https://www.cnblogs.com/over140/p/5462580.html
Copyright © 2011-2022 走看看