可在iOS 7和iOS 8上运行的警报 [英] Alert that can work on iOS 7 and iOS 8

查看:130
本文介绍了可在iOS 7和iOS 8上运行的警报的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在得到dyld:未找到符号:_OBJC_CLASS _ $ _ UIAlertAction
当我试图让这个怪物运行时。

I'm getting dyld: Symbol not found: _OBJC_CLASS_$_UIAlertAction when I'm trying to get this monstrosity to run.

我如何弱连接8.0东西?

How do I weaklink 8.0 stuff?

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必须标记为Optional而不是Required。简化版现在是:

Resolved: UIKit had to be marked Optional rather than Required. Simplified version is now:

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)
}


推荐答案


  • 在项目构建阶段的Link Binary With Libraries部分中明确添加UIKit。

    • Explicitly add UIKit in the "Link Binary With Libraries" section of your project's build phases.

      您可以测试UIAlertController的存在,如下所示:

      You can test for the existence of UIAlertController like this:

      if NSClassFromString("UIAlertController") != nil {
          // Use it
      } else {
          // Fall back
      }
      


    • 我写了一个包装器适用于iOS 7和iOS 8.您可以在此处找到它。它需要一个视图控制器,后跟一堆可选参数和任意数量的按钮:

    • I wrote a wrapper that works on both iOS 7 and iOS 8. You can find it here. It takes a view controller followed by a bunch of optional arguments and any number of buttons:

      showAlert(self, style: .ActionSheet, sourceView: cell, completion: {
          tableView.deselectRowAtIndexPath(indexPath, animated: true)
      },
          (.Default, "Send clipboard", {
              if someCondition {
                  // completion must be specified because of a Swift bug (rdar://18041904)
                  showAlert(self, title: "Nothing to send", message: "The clipboard is empty.", completion: nil,
                      (.Cancel, "OK", nil)
                  )
              }
          }),
          (.Cancel, "Cancel", nil)
      )
      


    • 这篇关于可在iOS 7和iOS 8上运行的警报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆