任何人都知道如何自定义 SwiftUI TextField 属性,例如拼写检查类型或自动更正类型?在不与 UIKit 交互的情况下做到这一点似乎是不可能的......
谢谢你们!
在今天早上安装Xcode 11 beta 5之后,我注意到它NavigationDestinationLink已不推荐使用NavigationLink。
另外,这就是苹果在发行说明中所说的:
NavigationDestinationLink和DynamicNavigationDestinationLink已弃用;它们的功能现在包含在NavigationLink中。(50630794)
我使用NavigationDestinationLink的方式是通过编程将新视图推入堆栈self.link.presented?.value = true。似乎没有该功能NavigationLink。
有人知道吗?我宁愿不再使用NavigationDestinationLink它,因为它已被弃用...
谢谢!
更新:
实际上,这种NavigationDestinationLink方式不再起作用,所以我想我们无法以编程方式进行推送了吗?
更新2:
NavigationLink(destination: CustomView(), isActive: $isActive) {
return Text("")
}
Run Code Online (Sandbox Code Playgroud)
这是可行的,但是当您传递isActive为true时,任何状态更新都将触发此代码并一遍又一遍地推送...此外,如果将其传递回false,它将弹出视图。不仅更新,如果将其设置isActive为true,它还将推动视图(良好),并且如果我们按后退按钮,它将返回并立即再次推动,因为它仍然是正确的。玩onAppear是我的希望,但是回到它时并没有被要求……我不确定我们应该如何使用它。
I am experimenting with SwiftUI and just trying to have a button at the bottom. Right now it is centered. Wondering how I could force a view to stick superview's bottom as you would do in AutoLayout.
struct ContentView : View {
var body: some View {
VStack {
Text("Test")
}
}
}
Run Code Online (Sandbox Code Playgroud)
Thank you!!!
另一个SwiftUI斗争!
我有一个包含列表的视图。当用户点击一行时,我想先将所选项目保存在我的VM中,然后再推送另一个视图。我能想到的解决该问题的唯一方法是,首先保存选定的行,然后使用另一个按钮来推送下一个视图。似乎仅需轻按一下即可完成此操作。
有人知道吗?
这是代码:
struct AnotherView : View {
@State var viewModel = AnotherViewModel()
var body: some View {
NavigationView {
VStack {
List(viewModel.items.identified(by: \.id)) { item in
NavigationLink(destination: DestinationView()) {
Text(item)
}
// Before the new view is open, I want to save the selected item in my VM, which will write to a global store.
self.viewModel.selectedItem = item
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢!