總結iOS 8和Xcode 6的各種坑

來源:互聯網
上載者:User

標籤:

總結iOS 8和Xcode 6的各種坑

項目路徑坑

模擬器的路徑從之前的 ~/Library/Application Support/iPhone Simulator 移動到了 ~/Library/Developer/CoreSimulator/Devices/ 這相當的坑爹,之前運行用哪個模擬器直接選擇這個模擬器檔案夾進去就能找到項目 

現在可好,Devices目錄下沒有標明模擬器的版本,圖片上選中的對應的可能是iPhone 5s 7.1的

然後圖片上的檔案夾對應的應該是 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到一個列表頁情況,結構如 

如果在列表頁需要隱藏tabbar,那麼我一般都會在這個VC把bottombar設定為none以便能更好的進行約束布局,

但是......在調試的時候你會發現進入列表頁的瞬間底部會出現一個tabbar高度的視圖。還是老老實實在就用預設的Inferred吧。

鍵盤彈不出

取消選擇Connect Hardware Keyboard

detailTextLabel無法顯示

先來下面這段代碼

1234567891011121314151617181920 - (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]; 一開始資料就是空的,解決辦法:

如果是空就不去設定值

123 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

 * 添加pch檔案,規則是: 項目名/xxxxx.pch

UIAlertView的坑

UIAlertView顯示無標題的長文本問題

12 UIAlertView *alterView = [[UIAlertView alloc] initWithTitle:nil message:@"遠端Git倉庫和標準的Git倉庫有如下差別:一個標準的Git倉庫包括了原始碼和曆史資訊記錄。我們可以直接在這個基礎上修改代碼,因為它已經包含了一個工作複本。" delegate:self cancelButtonTitle:@"知道了" otherButtonTitles:nil, nil];[alterView show];

上面這段代碼在iOS 8下顯示的樣子是這樣的,內容完全頂到的頂部,文字還莫名其妙的加粗了

難道我會告訴你只要把title設定為 @"" 就行了嗎 

12 UIAlertView *alterView = [[UIAlertView alloc] initWithTitle:@"" message:@"遠端Git倉庫和標準的Git倉庫有如下差別:一個標準的Git倉庫包括了原始碼和曆史資訊記錄。我們可以直接在這個基礎上修改代碼,因為它已經包含了一個工作複本。" delegate:self cancelButtonTitle:@"知道了" otherButtonTitles:nil, nil];[alterView show];
 掃一掃訂閱每日移動開發及APP推廣熱點資訊
公眾號:CocoaChina

總結iOS 8和Xcode 6的各種坑

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.