【问题标题】:Receiver type "WkAlertAction" for class message is a forward declaration类消息的接收器类型“WkAlertAction”是前向声明
【发布时间】:2017-10-30 17:36:10
【问题描述】:

在我的 watchos 应用中,我正在尝试使用 WkAlertAction,但遇到了这个问题。我附上了快照以供参考。

类消息的接收者类型“WkAlertAction”是前向声明

这是什么意思?我究竟做错了什么?

【问题讨论】:

    标签: ios watchkit watchos-2


    【解决方案1】:

    该错误告诉您只声明了相关类,但没有找到定义。例如,如果您在标头中声明带有@class WKAlertAction 的类,则会发生这种情况,因为它是参数的类型。但是,一旦您尝试实际使用它,即向实现中的对象发送消息,就会收到此错误,因为编译器找不到该类的实际定义。

    没有看到你的整个代码我不能肯定地说,但我猜你只是忘记包含框架或模块。确保您在相关范围内的某处有 @import WatchKit;,即可能在您看到错误的实现文件中。

    【讨论】:

      【解决方案2】:

      在检查了我的另一个 Watchos 项目后,我发现了我所做的问题。

      我在这里附上目标会员的图片。

      根据上面的错误,我的watchos项目在watchos扩展和ios扩展中都被选中了。 (WKAlertAction 类在 ios 中不可用,在 Watchos 中可用)。

      只是我像这样取消了目标成员资格。

      现在我的 WKAlertAction 运行良好。

      【讨论】:

        【解决方案3】:

        我正在寻找 swift 并弹出这个问题 所以我会在使用时添加对我有用的快速结果

        WKAlertAction

        watchOS 4.0

        斯威夫特 4

                let action1 = WKAlertAction.init(title: "Cancel", style:.cancel) {
                    print("cancel action")
                }
                
                let action2 = WKAlertAction.init(title: "default", style:.default) {
                    print("default action")
                }
                
                let action3 = WKAlertAction.init(title: "destructive", style:.destructive) {
                    print("destructive action")
                }
                
                presentAlert(withTitle: "Alert Title", message: "message is here", preferredStyle:.actionSheet, actions: [action1,action2,action3])
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-11-07
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多