您现在的位置是:首页 > 文章详情

【Swift 2.2】iOS开发笔记(三)

日期:2017-12-03点击:517

1、UITableView 中调用 UIButton 的 setTitle 会闪

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

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 

1
2
3
4
5
6
7
8
9
10
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 {

           }

本文转自博客园农民伯伯的博客,原文链接:【Swift 2.2】iOS开发笔记(三),如需转载请自行联系原博主。



原文链接:https://yq.aliyun.com/articles/327368
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章