zoukankan      html  css  js  c++  java
  • 转载:总结iOS 8和Xcode 6的各种坑

    项目路径坑

    模拟器的路径从之前的 ~/Library/Application Support/iPhone Simulator 移动到了 ~/Library/Developer/CoreSimulator/Devices/ 这相当的坑爹,之前运行用哪个模拟器直接选择这个模拟器文件夹进去就能找到项目 

    aM7ZjiV.png

    现在可好,Devices目录下没有标明模拟器的版本,图片上选中的对应的可能是iPhone 5s 7.1的

    bVkl5m.png

    然后图片上的文件夹对应的应该是 iPhone 4s 7.1 iPhone 4s 8.0 iPhone 5s 7.1 iPhone 5s 8.0 .......,但是我不知道哪个对应哪个啊,好吧我要疯了

    NSUserDefaults坑

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

    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.

    添加以下代码可解决

    1
    self.tableView.rowHeight = 44.0f;

    autolayout坑

    典型的UITabBarController作为根视图,然后点击其中一个页面button的时候push到一个列表页情况,结构如下图 

    iumEBn.jpg

    如果在列表页需要隐藏tabbar,那么我一般都会在这个VC把bottombar设置为none以便能更好的进行约束布局,

    bVkl5s.png

    但是......在调试的时候你会发现进入列表页的瞬间底部会出现一个tabbar高度的视图。还是老老实实在就用默认的Inferred吧。

    键盘弹不出

    RfEnqay.png

    取消选择Connect Hardware Keyboard

    detailTextLabel无法显示

    先来下面这段代码

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    - (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]; 一开始数据就是空的,解决办法:

    如果是空就不去设置值

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

    或者

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

    pch文件不见了

    现在Xcode 6创建的项目默认是不带pch文件的,当然了旧版本的项目是会保留的。那么如何添加pch文件?

    * Command + N 然后在Other里面选择 PCH File

    * 在Build Settings里面找到  Prefix Header

    aMFVjm.jpg

     * 添加pch文件,规则是: 项目名/xxxxx.pch

    UIAlertView的坑

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

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

    上面这段代码在iOS 8下显示的样子是这样的,内容完全顶到的顶部,文字还莫名其妙的加粗了

    ZFbaIj.png

    难道我会告诉你只要把title设置为 @"" 就行了吗 

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

    转载自:http://www.cocoachina.com/ios/20141218/10681.html

  • 相关阅读:
    Jmeter beanshell preprocessor随机添加任意多个请求参数
    Jmeter 场景设计
    jmeter 参数化
    .net 匿名方法
    jmeter 运行脚本报错 java.net.BindException: Address already in use
    Jmeter mysql性能测试
    ngcordova 监控网络制式改变
    建立apk定时自动打包系统第一篇——Ant多渠道打包并指定打包目录和打包日期
    Kafka架构
    Linux命令
  • 原文地址:https://www.cnblogs.com/iOSCain/p/4282901.html
Copyright © 2011-2022 走看看