总结iOS 8和Xcode 6的各类坑

项目路径坑

模拟器的路径从以前的~/Library/Application Support/iPhone Simulator移动到了~/Library/Developer/CoreSimulator/Devices/这至关的坑爹,以前运行用哪一个模拟器直接选择这个模拟器文件夹进去就能找到项目ios%207%20path.png
如今可好,Devices目录下没有标明模拟器的版本,图片上选中的对应的多是iPhone 5s 7.1的iOS%208.png
而后图片上的文件夹对应的应该是iPhone 4s 7.1 iPhone 4s 8.0 iPhone 5s 7.1 iPhone 5s 8.0.......,可是我不知道哪一个对应哪一个啊,好吧我要疯了ios


NSUserDefaults坑

经过NSUserDefaults储存在本地的数据,在模拟器删除APP、clean以后没法清空数据,我尝试删除iPhone 4s、iPhone 5s......里面的同一个项目,仍是无解,这应该是个BUG,等苹果更新Xcode吧(我目前用的6.0)。可是真机没有这种状况(必须的啊)ide


UITableView坑

带有UITableView的界面若是到遇到如下警告布局

Warning once only: Detected a case where constraints ambiguously suggest a height of zero for a tableview cell's content view. We're considering the collapse unintentional and using standard height instead.测试

添加如下代码可解决ui

self.tableView.rowHeight = 44.0f;

autolayout坑

典型的UITabBarController做为根视图,而后点击其中一个页面button的时候push到一个列表页状况,结构以下图storyboard.jpg
若是在列表页须要隐藏tabbar,那么我通常都会在这个VC把bottombar设置为none以便能更好的进行约束布局,bottombar.png可是......在调试的时候你会发现进入列表页的瞬间底部会出现一个tabbar高度的视图。仍是老老实实在就用默认的Inferred吧。spa


键盘弹不出

keyboard.png取消选择Connect Hardware Keyboard调试


detailTextLabel没法显示

先来下面这段代码code

- (void)viewDidLoad
{
    [super viewDidLoad];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        self.array = @[@"测试"];
        [self.tableView reloadData];
    });
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TradeRecordCell"
                                                            forIndexPath:indexPath];
    cell.detailTextLabel.text = _array[indexPath.row];
    return cell;
}

代码没什么问题,在iOS 7下,一秒以后cell的detailTextLabel就会显示测试两个字,可是在iOS 8却不行detailTextLabel显示为空。测试发现,当detailTextLabel的text一开始为空,iOS 8下运行就会把这个label的size设置(0, 0)从而不能正确显示,缘由是这里cell.detailTextLabel.text = _array[indexPath.row];一开始数据就是空的,解决办法:图片

若是是空就不去设置值get

if (_array[indexPath.row]) {
        cell.detailTextLabel.text = _array[indexPath.row];
    }

或者

cell.detailTextLabel.text = _array[indexPath.row] ? : @" ";

pch文件不见了

如今Xcode 6建立的项目默认是不带pch文件的,固然了旧版本的项目是会保留的。那么如何添加pch文件?
* Command + N 而后在Other里面选择PCH File
* 在Build Settings里面找到Prefix Headerpch.jpg
* 添加pch文件,规则是: 项目名/xxxxx.pch


UIAlertView的坑

UIAlertView显示无标题的长文本问题

UIAlertView *alterView = [[UIAlertView alloc] initWithTitle:nil message:@"远端Git仓库和标准的Git仓库有以下差异:一个标准的Git仓库包括了源代码和历史信息记录。咱们能够直接在这个基础上修改代码,由于它已经包含了一个工做副本。" delegate:self cancelButtonTitle:@"知道了" otherButtonTitles:nil, nil];
[alterView show];

上面这段代码在iOS 8下显示的样子是这样的,内容彻底顶到的顶部,文字还莫名其妙的加粗了alert.png
难道我会告诉你只要把title设置为@""就好了吗

UIAlertView *alterView = [[UIAlertView alloc] initWithTitle:@"" message:@"远端Git仓库和标准的Git仓库有以下差异:一个标准的Git仓库包括了源代码和历史信息记录。咱们能够直接在这个基础上修改代码,由于它已经包含了一个工做副本。" delegate:self cancelButtonTitle:@"知道了" otherButtonTitles:nil, nil];
[alterView show];
相关文章
相关标签/搜索