swiftui - VStack 中的按钮和文本
问题描述
我正在尝试在 SwiftUI 中定义以下视图,但它不起作用:
struct ContentView: View {
var body: some View {
Text("Placeholder")
Button(action: {
// Do something
}) {
Text("Button")
}
}
}
错误是:
Function declares an opaque return type, but has no return statements in its body from which to infer an underlying type
还有两个警告:
Result of 'Text' initializer is unused
和
Result of 'Button<Label>' initializer is unused
我正在尝试在带有 OS Catalina 的 Mac 上使用 XCode11 进行编码。有谁知道问题是什么?
解决方案
你忘了添加提到的VStack
var body: some View {
VStack { // << here !!
Text("Placeholder")
Button(action: {
// Do something
}) {
Text("Button")
}
}
}
推荐阅读
- python - 如何使用重复的行和条件来更新列?
- python - 具有不同滞后算子的向量自回归 (VAR) 模型拟合
- react-admin - 发送 PATCH 请求时 React-admin 排除字段
- javascript - 在具有相同类的两个单独元素上具有相同的功能
- node.js - 如何正确错误处理谷歌云语音识别调用?
- javascript - TMDB API 在 ReactJS 中显示相同的数据
- encryption - MariaDB - 如何确认静态数据已加密?
- javascript - 如何正确格式化 morris js 的数据
- python - 使用 Pandas 创建日期列,使用 asfreq 填充特定时期之间的日期间隔
- swiftui - SwiftUI 中的 viewWillAppear() 或其他等效项