swift - SwiftUI 中的静态项目列表
问题描述
我正在使用Xcode Version 12.3 (12C33)
并且正在尝试添加带有项目的静态列表。我只能编译我的项目一次,它实际上工作得很好,现在我遇到了一些奇怪的错误。我在下面做了一个简单的代码示例,即使这样也给了我在其他项目中看到的相同错误。我错过了一些简单的东西吗?
struct ContentView: View {
var body: some View {
List {
Text("Item 1")
Text("Item 2")
Text("Item 3")
}
}
}
Return type of property 'body' requires that 'List' conform to 'View'
Static method 'buildBlock' requires that 'List' conform to 'View'
Trailing closure passed to parameter of type Decoder that does not accept a closure.
解决方案
在 SWIFTUI 中列出代码*
struct RestRow: View {
var name: String
var body: some View {
Text("Restaurant: \(name)")
}
}
struct ContentView: View {
var body: some View {
List {
RestRow(name: "ITEM # 1")
RestRow(name: "ITEM # 2")
RestRow(name: "ITEM # 3")
}
}
}
推荐阅读
- php - 为什么在为文件创建备份 tar 时出现“构建步骤‘执行外壳’将构建标记为失败”错误
- swift - 我可以使用 UISearchController 来选择 API 参数(然后相应地填充单元格),而不是过滤现有单元格吗?
- bash - `-s --` 标志对 npm 有什么作用?
- sql - 为什么我不能在golang中使用多个参数我的sql查询有什么问题?
- bash - 如何检测 docker run 和底层守护程序是否以编程方式完全启动?
- c# - 在 ASP.NET Core 2.2 和 ASP 之间共享 Cookie 身份验证。没有 Microsoft.Identity 的 NET MVC 5 (.NET Framework 4.6.1)
- django - 使用 Django 模型中的字段对数据进行计算
- junit - 如何在扩展中使用 TempDir
- css - .SCSS 文件中的数学计算 Angular CLI 不起作用
- php - 如何在同一服务器上的 Web 应用程序(核心 PHP)和另一个 Web 应用程序(Laravel)之间共享会话?