相关疑难解决方法(0)

SwiftUI NavigationView navigationBarTitle LayoutConstraints 问题

这可能与最近推出的新 (12.3) 版本的 XCode 相关,但我有一个非常简单的 SwiftUI 视图:

import SwiftUI

struct HomeView: View {
    var body: some View {
        NavigationView {
            Text("Text")
                .navigationBarTitle("My Title")
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我在控制台中收到此警告:

2020-12-15 18:25:06.506062-0800 Shopmatic[46177:9585655] [LayoutConstraints] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. 
    Try this: 
        (1) look at each constraint and try to figure out which you don't expect; 
        (2) find the code that added the unwanted constraint or constraints and …
Run Code Online (Sandbox Code Playgroud)

ios swift swiftui

53
推荐指数
7
解决办法
6862
查看次数

如何使TextField成为第一响应者?

这是我的代码...

struct ContentView : View {
    @State var showingTextField = false
    @State var text = ""
    var body: some View {
        return VStack {
            if showingTextField {
                TextField($text)
            }
            Button(action: {
                self.showingTextField.toggle()
            }) {
                Text ("Show")
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我想要的是当文本字段变为可见时,使文本字段成为第一响应者(即,获得焦点并弹出键盘)。

swift swiftui

31
推荐指数
10
解决办法
3078
查看次数

标签 统计

swift ×2

swiftui ×2

ios ×1