總結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];
相關文章
相關標籤/搜索