11.自适应文本高度
NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:]}; CGRect rect = [text boundingRectWithSize:CGSizeMake(ViewWidth, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:attributes context:nil]; return rect.size.height;
12 iOS9 适配设置
实际上在Xcode 7中,我们新建一个iOS程序时,bitcode选项默认是设置为YES的。我们可以在”Build Settings”->”Enable Bitcode”选项中看到这个设置。
要么让第三方库支持,要么关闭target的bitcode选项。
13. iOS9 HTTPs转HTTP
<key>NSAppTransportSecurity</key> <dict> <!--Connect to anything (this is probably BAD)--> <key>NSAllowsArbitraryLoads</key> <true/> </dict>
14.截取字符串
[str substringFromIndex:6];
substringWithRange:NSMakeRange(4,2)截取字符串的一部分,从第4位开始,截取两位
substringToIndex: n截取到第几位
(substringFromIndex:n)字符串从第n 位开始截取,直到最后
16.NSScanner: nil string argument
错误原因是我们在调用某个方法的时候,传入了一个空字符串(注意区别于字符串内容为空)作为方法参数。
我从服务器上获取某字符串数据,考虑到有些对象不含这个字符串变量,我在使用时先判断该字符串是否为空,例如:
假设,这个字符串名叫str,
先判断if(str!=nil){
//do something
double data=[str doubleValue];
}
但是,当数据为空时依旧报错,
苹果官方文档时,有这么一个代码:
- id aValue = [arrayWithNull objectAtIndex:0];
- if (aValue == nil) {
- NSLog(@"equals nil");
- } else if (aValue == [NSNull null]) {
- NSLog(@"equals NSNull instance");
- if ([aValue isEqual:nil]) {
- NSLog(@"isEqual:nil");
- }
- }
- // output: "equals NSNull instance”
虽然最后我的问题解决了,我在if判断中用
- if(![tmpNewsModel.latitude isEqual:[NSNull null]]){
- //do something
- }
问题是解决了,但是还不太理解nil和NSNull的区别?
17.iphone 尺寸
18.修改mac host文件
sudo nano /etc/hosts
同样是输入密码,打开 hosts 文件,根据你的需要对该文件进行编辑,编辑完毕之后按 ctrl+o 保存,
出现 File Name to Write: /etc/hosts 的时候按回车确认,再按 ctrl+x 退出即可。
19. IOS8 设置TableView Separatorinset 分割线从边框顶端开始
经过测试加入下面方法 在ios7 8上都可以正常工作
-(void)viewDidLayoutSubviews { if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) { [self.tableView setSeparatorInset:UIEdgeInsetsMake(,,,)]; } if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) { [self.tableView setLayoutMargins:UIEdgeInsetsMake(,,,)]; } } -(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { if ([cell respondsToSelector:@selector(setSeparatorInset:)]) { [cell setSeparatorInset:UIEdgeInsetsZero]; } if ([cell respondsToSelector:@selector(setLayoutMargins:)]) { [cell setLayoutMargins:UIEdgeInsetsZero]; } }
20.url 里面不能有中文字符,需转换否会请求出错