【问题标题】:cannot find uiviewcontrollerrepresentable in scope在范围内找不到 uiviewcontrollerrepresentable
【发布时间】:2022-03-04 03:13:56
【问题描述】:

我的应用有一个 WatchKit 扩展,我需要使用手机上应用的更新来修改内容视图中的数据。所以我使用下面的代码......但是编译器错误说它可以在范围内找到 UViewControllerRepresentable

struct ContentView: View, UViewControllerRepresentable
  {
  
  
  var body: some View {
    VStack
      {
          ...
      }
  }

【问题讨论】:

  • \嗨,斯科特,您是否检查了目标成员中的两个目标?它在检查器视图中。
  • 请提供足够的代码,以便其他人更好地理解或重现问题。

标签: swiftui watchkit watch watchconnectivity


【解决方案1】:

UIViewControllerRepresentable 无法观看。

https://developer.apple.com/documentation/swiftui/uiviewcontrollerrepresentable

没有必要,因为 WatchKit/WatchOS 没有 UIViewControllers https://developer.apple.com/documentation/uikit/uiviewcontroller

SwiftUI Views 可用但不能使用UIKitUIViews/UIViewControllers

当您必须为兼容 watchOS 的版本重新设计 View 时,您可以将其命名为与 iOS 目标版本相同的名称,并将其命名为相同的 init

如果您选择适当的目标成员资格,编译器将选择当前目标的版本。

【讨论】:

  • 非常感谢。如何使用来自手表连接的应用程序更新数据更新视图?
  • @ScottTarone 这是一个不同的问题,您可以查看here 寻求帮助。如果我回答了你的问题,你能接受上面的答案吗?它是绿色的复选标记。
  • 谢谢你的帮助,我去看看
猜你喜欢
  • 2020-11-23
  • 2021-06-18
  • 2021-01-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多