我得到dyld:找不到符號:_OBJC_CLASS _ $ _ UIAlertAction 當我試圖讓這個怪物運行。警報,可以在iOS 7和iOS 8上工作
如何弱化8.0的東西?
var device : UIDevice = UIDevice.currentDevice()!;
var systemVersion = device.systemVersion;
var iosVerion : Float = systemVersion.bridgeToObjectiveC().floatValue;
if(iosVerion < 8.0) {
let alert = UIAlertView()
alert.title = "Noop"
alert.message = "Nothing to verify"
alert.addButtonWithTitle("Click")
alert.show()
} else {
var alert : UIAlertController? = UIAlertController(title: "Noop", message: "Nothing to verify", preferredStyle: UIAlertControllerStyle.Alert)
if alert {
let actionStyle : UIAlertActionStyle? = UIAlertActionStyle.Default;
var alertAction : UIAlertAction? = UIAlertAction(title: "Click", style: actionStyle!, handler: nil)
if(alertAction) {
alert!.addAction(alertAction)
self.presentViewController(alert, animated: true, completion: nil)
}
}
}
return;
解決:UIKit必須標記爲「可選」而非「必需」。現在簡化版本是:
var device : UIDevice = UIDevice.currentDevice()!;
var systemVersion = device.systemVersion;
var iosVerion : Float = systemVersion.bridgeToObjectiveC().floatValue;
if(iosVerion < 8.0) {
let alert = UIAlertView()
alert.title = "Noop"
alert.message = "Nothing to verify"
alert.addButtonWithTitle("Click")
alert.show()
} else {
var alert : UIAlertController = UIAlertController(title: "Noop", message: "Nothing to verify", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Click", style:.Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
}
的[錯誤表示迅速一個UIAlertView中](http://stackoverflow.com/questions/24040519/error-showing-a-uialertview-in-swift) – Daniel
這可能重複的是該問題的一個超集你已經提到。有人曾建議 設警報= UIAlertView中() alert.title = 「NOOP」 alert.message = 「無驗證」 alert.addButtonWithTitle( 「點擊」) alert.show() 這工作了我。有人應該肯定找到一個與蘋果有關方便inti破壞UIAlertView墊片的錯誤 –
請看看我在這裏發表的答案: [http://stackoverflow.com/a/24091779/1485344][1] [1]:http://stackoverflow.com/a/24091779/1485344 –