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

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(controllerUIViewController) {

        let stackViewControllers NSMutableArray(arrayself.viewControllers)

        stackViewControllers.removeLastObject()

        stackViewControllers.addObject(controller)

        setViewControllers((stackViewControllers as NSArrayas! [UIViewController], animatedtrue)

    }

 

}

  如果先 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开发笔记(三),如需转载请自行联系原博主。

时间: 2024-08-14 04:20:39

【Swift 2.2】iOS开发笔记(三)的相关文章

【Swift】iOS开发笔记(一)

1.隐藏/显示密码功能 光设置secureTextEntry还不行,你会发现UITextField在切换到显示密码时会多一个空字符,看着巨别扭,需要在更改secureTextEntry后进行如下设置:         let pwd = psdField.text         self.psdField.text = pwd + " "         self.psdField.text = pwd 2.获取当前类的名称 String.fromCString(object_get

IOS开发笔记 IOS如何访问通讯录

    IOS开发笔记  IOS如何访问通讯录 其实我是反对这类的需求,你说你读我的隐私,我肯定不愿意的. 幸好ios6.0 以后给了个权限控制.当打开app的时候你可以选择拒绝. 实现方法: [plain] view plaincopy //读取所有联系人      -(void)ReadAllPeoples      {              //取得本地通信录名柄              ABAddressBookRef tmpAddressBook = nil;         

小白求解-努力学习ios开发中大三。专科 大家觉得有前途吗?

问题描述 努力学习ios开发中大三.专科 大家觉得有前途吗? 希望大神给点建议 以后在北京.我觉得ios都是不那么好学.感觉自己逻辑特别差.又笨 能学好吗? 解决方案 先自学 再去培训机构学 这样好一些 我认为只要是正常人 想学都能学会 除非实在没辙的

.Net WInform开发笔记(三)谈谈自制控件(自定义控件)_C#教程

末日这天写篇博客吧,既然没来,那就纪念一下. 这次谈谈自制控件,也就是自定义控件,先上图,再说 1.扩展OpenFileDialog,在OpenFileDialog中添加各种文件(.txt,.jpg,.excel等等)的预览功能 开发笔记(三)谈谈自制控件(自定义控件)_C#教程-winform自定义控件"> 2.重写ListBox,增加折叠.鼠标背影.分类等功能 -----------------------------分割线-------------------------------

IOS开发笔记

1 iphone开发笔记 2 3 退回输入键盘 4 - (BOOL) textFieldShouldReturn:(id)textField{ 5 [textField resignFirstResponder]; 6 } 7 8 CGRect 9 CGRect frame = CGRectMake (origin.x, origin.y, size.width, size.height):矩形 10 NSStringFromCGRect(someCG) 把CGRect结构转变为格式化字符串:

IOS开发笔记整理49之详解定位CLLocation_IOS

在项目功能中有一个定位CLLocation的需求,遇到了一些知识难点,经过各位大侠的帮助,问题解决,特此分享供大家学习,希望大家共同学习进步. 一.简单说明 1.CLLocationManager CLLocationManager的常用操作和属性 开始用户定位- (void)startUpdatingLocation; 停止用户定位- (void) stopUpdatingLocation; 说明:当调用了startUpdatingLocation方法后,就开始不断地定位用户的位置,中途会频繁

iOS开发笔记--详解UILabel的相关属性设置_IOS

在iOS编程中UILabel是一个常用的控件,下面分享一下UILabel的相关属性设置的方法. 很多学习iOS6编程都是从storyboard开始,用到UILabel时是将控件拖到storyboard中生成实现,如果想要在-(void)viewDidLoad中用代码如[_label initWithFrame:CGRectMake(X,Y,WIDTH,HEIGHT)]方法改变拖拽到storyboard的label的大小是行不通的,因为程序加载时先执行了-(void)viewDidLoad的代码,

iOS开发笔记 6、View Controllers【MVC】

了解和熟悉这个对后续的开发很重要.   关于这个的参考资料 ■ View Controller Programming Guide for iOS For information about structuring and managing your application's user interface http://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/ViewControl

iOS开发笔记 7、数据【Preferences、文件、库、Core Data】

程序开发中根据要使用各种各样的数据,如配制.文件系统.数据库等,iOS对这个有很好的支持 Preferences If you're going to create a program that has built-in preferences, you should do so using the Utility Application template. To create the special cartouched list used by preferences, you must c