zoukankan      html  css  js  c++  java
  • swift学习经验和错误记录

    1、selector 和action 直接用字符串,后面要加冒号":"

    2、StoryBoard 连接后改名又重新连接出现了找不到符号的诡异错误,unknow class xxxx view in interfacebuilder 删掉连接后重新连接

    3、可以从StoryBoard里提取View但是这个view要是viewcontroller的rootview,如果不是rootview可能会崩溃

    4、自定义xib在view出写上自定义类,而不是file owener

    5、controller切换时,show可以继承上一个的导航栏,而present不会

    6、修改UISegmentControl 的字体设置

            let attrib = [NSFontAttributeName: UIFont.boldSystemFontOfSize(16), NSForegroundColorAttributeName:UIColor.blackColor()]

            segControl!.setTitleTextAttributes(attrib, forState: UIControlState.Normal)

            segControl!.setTitleTextAttributes(attrib, forState: UIControlState.Selected)

    7、使用autolayout事,tableview上有时候会有一个空白,可以让tableview得上部对齐由top layou 改为super view

    8、 iOS Xcode, 解决“Could not insert new outlet connection”的问题,参考此文,还有一种说法是对应的类没有加到target里,不过这种情况很少。

    9、NSURL(string: str)为nil原因因为str里面有中文,所以NSURL无法识别增加编码格式

    str = (str as NSString).stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)

    10、UICollectionView的注意事项

      a、要collectionView.registerClass(ScheduleCell.classForCoder(), forCellWithReuseIdentifier: identifier)

      b、点击时获取cell

        func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {

            let cell = collectionView.cellForItemAtIndexPath(indexPath) as ScheduleCell

      //不能用 collectionView.dequeueReusableCellWithReuseIdentifier(identifier, forIndexPath: indexPath) as ScheduleCell 否则都是新建的了,至于原因不知,还望大侠赐教

        }

    11、ios uitextfield uitextinput 不弹出软键盘  模拟器设置里面 Hardware - keyboard 内设置了 链接电脑键盘。你可以点击第三个:toggle software keyboard让虚拟机弹出,或者把 connect hardware keyboard 不勾选,这样就能自动弹出虚拟键盘了(不过电脑键盘就输入不了了) 

    12、transform 时如果 点在下边,向下拖动,会先向上移动一下。

    13、w、h不同storyboard会有不同的配置,切换不同的配置,会变灰

    14、Swift 默认参数和外部名一致可以不用#,如果是inout参数用&

    注意整型Int32 和Int的区别

  • 相关阅读:
    网站被刷导致404解决
    vim常用
    curl, wget常用选项
    使用paramiko远程登录并执行命令脚本
    批量监测dns是否可用脚本,不可用时并切换
    shell脚本收集服务器基本信息并入库
    沃通SSL证书及国密SSL证书入驻百度云市场
    电子合同,相比纸质合同有哪些好处?
    DV型域名https证书的优点及申请流程
    Chrome 浏览器显示“网站连接不安全”,是什么原因?
  • 原文地址:https://www.cnblogs.com/xdao/p/swift_ios_experience.html
Copyright © 2011-2022 走看看