手机浏览 RSS 2.0 订阅 膘叔的简单人生 , 腾讯云RDS购买 | 超便宜的Vultr , 注册 | 登陆
浏览模式: 标准 | 列表2014年12月14日的文章

supportedInterfaceOrientations

在OC下写这个真方便。。

 

- (NSInteger) supportedInterfaceOrientations{
     return (UIInterfaceOrientationsMaskPortrait | UIInterfaceOrientationsMaskLandscapeLeft);
}
 
在swift下就。。苦逼了
override func supportedInterfaceOrientations -> Int{
     //错误写法 return (UIInterfaceOrientationsMask.Portrait | UIInterfaceOrientationsMask.LandscapeLeft);
     //上面会报错。。说是UIInterfaceOrientationsMask不能转成Bool
     //google了一下,原来,,,应该这样写
     return UIInterfaceOrientationMask.Portrait.rawValue.hashValue | UIInterfaceOrientationMask.PortraitUpsideDown.rawValue.hashValue;
}
天啊要写这么上。开始网上是写UIInterfaceOrientationMask.Portrait.toRaw().hashValue,但好象toRaw的方法新版没有了。
所以只能用rawValue来转换。
好辛苦啊。swift改了N次了

UIActionSheetView和UIAlertView

 笔记

这两个View都有一个参数 :otherButtonTitles,在OC中的时候,如果这个参数 不设置就是otherButtonTitles:nil,
如果有多个参数 ,就是otherButtonTitles: @"first" , @"second" , nil
就因为这个nil,害得我在swift里走了弯路
 
在写swift的时候,我也是otherButtonTitles:nil的时候直接就报错了,说是不能转成String,再看了一下方法,果然人家写的就是otherButtonTitles:String?
那怎么办?想了一阵,那我不写这个参数行不行?最后果然OK。那么,如果是多个button咋整?
放弃nil吧?otherButtonTitles:"abc","def","ghi"
果然编译通过。。。原代码中的nil真是吓坏我了
 
我在看精通IOS开发第6版。初学。100页还没看完。不过我是全部用swift写的,好累啊@
 

Tags: swift

IOS开发笔记(swift)二

1、 如何获取字符串的长度:

在判断长度是否大于0的时候,if [xxx length ] > 0 就行了。而如果直接用swift,就不能写 if xxx.length > 0 了。因为xxx没有length这个方法。
有两个办法:
  1. if countElements(xxx) > 0 
  2. if xxx.utf16count > 0 
2、swift的delegate不象oc那样一个个的标注,只要在class头上写明就OK了
比如 class ViewController : UIViewController , UIActionSheetDelegate {

}
就能直接用UIActionSheetDelegate中的方法了。然后他们的delegate写self即可

刚开始学。不知道对错,目前就这样先纯做笔记,当然 你也可以delegate: nil 这样代表你这个控件 就不再接受委托了

Tags: swift