【发布时间】:2014-07-26 08:22:57
【问题描述】:
我得到 dyld:找不到符号:_OBJC_CLASS_$_UIAlertAction 当我试图让这个怪物运行时。
我如何弱链接 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)
}
【问题讨论】:
-
这是您提到的问题的超集。其他人建议 let alert = UIAlertView() alert.title = "Noop" alert.message = "Nothing to verify" alert.addButtonWithTitle("Click") alert.show() 这对我有用。肯定有人应该找到 Apple 关于 UIAlertView shim 上的便利性 inti 损坏的错误
-
我做到了。引用的条目与 UIAlertView 的初始化有关。我的参赛作品与吃蛋糕和吃蛋糕有关。
-
“UIKit 必须标记为可选而不是必需”是什么意思?
标签: ios backwards-compatibility swift