2015-04-22 22 views
0

我使用SDK 6.4和Target 7.1的Xcode 6.3 beta4。當目標爲7.0時,Xcode提出「EXC_BAD_ACCESS code = 1」

運行一個簡單的線條就像在iOS 7.1模擬器或設備的以下引發錯誤:

let alert = UIAlertController(title: "title", message: "message", preferredStyle: .Alert) 

的錯誤是:

EXC_BAD_ACCESS code=1 

,當我在一個運行不發生錯誤iOS 8.4模擬器。

似乎是由不同的SDK版本引起的衝突。

如何防止iOS版本7.x在目標上運行EXC_BAD_ACCESS code=1錯誤?

編輯:Xcode中顯示我:

enter image description here

如何調試這樣的錯誤?

回答

4

UIAlertViewiOS7已與UIAlertControlleriOS8上取代。

你的是什麼,我會建議做的,爲了解決兼容性問題如下

if objc_getClass("UIAlertController") != nil { 

     println("UIAlertController can be instantiated") 

      //make and use a UIAlertController 

    } 
    else { 

      println("UIAlertController can NOT be instantiated") 

      //make and use a UIAlertView 
    } 
2
UIAlertController 

僅在iOS 8.0及以上版本有效。所以,你必須有一個分割使用UIAlertView爲iOS 7

+0

或者只使用UIAlertView中無處不在,不打擾UIAlertController。這樣你也可以確保你的代碼被正確測試;很容易在兩個版本的代碼中有一個出現錯誤。 – gnasher729

相關問題