Also works without any problems on macos 12.beta, xcode 13.beta, target ios 15 and macCatalyst 12.
Tested on macOS 12 and iPhone ios 15.
Post
Replies
Boosts
Views
Activity
cannot delete my post sorry.
there seem to be a lot of things not working properly with NavigationView/NavigationLink judging by the number of unresolved questions and strange workarounds.
You can do this however, to let you select which list to go back to:
struct InnerListView: View {
var body: some View {
NavigationView { // <--- here
List(1..<100) { row in
NavigationLink(destination: Text("Details for row \(row)")) {
Text("Row \(row)")
}
.navigationTitle("Inner List")
}
}
}
}
seeing the same problem.
There is no "major" mistake in your code. However,
with querying parameters in http, you have to use "?" to indicate this is
a query string. If you have more than one parameter you need to separate them with "&".
Something like:
URL(string: "https://mysite.com/product?id=" + productId)
You need to find out exactly how to query the server with productId.
in your data structure you don't have a hierarchy of parent/children, you only have a flat
array of MapLayerGroup each element containing an array of LayerGroup. So I guess the compiler
cannot make sense of the non tree-structured data. Try a simple list in this case:
List(mapLayerGroups, id: \.id) { layer in
Text(layer.Name)
}
If your intention was to have a tree structure hierachy, then you should have something like this:
struct MapLayerGroup: Hashable, Identifiable {
var id = UUID()
var children: [MapLayerGroup]? = nil // <---
var CanBeDeleted: Bool
var ListOrder: Int
var Mutual: Bool
var Name: String
var ProjectId: Int
var ProjectLayerGroupId: Int
var Xaml: String
var LayerGroups: [LayerGroup]?
}
...
List(mapLayerGroups, children: \.children) { layer in
Text(layer.Name)
}
See also the Apple doc (halfway down the page) at:
Apple Documentation
just an observation, you are not getting 3, it's 3e-05 = 0.00003 a very small number.
I would try something like this:
import SwiftUI
@main
struct TestApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
struct ContentView: View {
var body: some View {
TextEditorView()
}
}
struct TextEditorView: View {
@State private var fullText: String = ""
@State private var undoText: [Character] = []
var body: some View {
VStack {
HStack {
Button(action: undoType) {Image(systemName:"arrow.uturn.backward")}
Button(action: redoType) {Image(systemName:"arrow.uturn.forward")}
}
TextEditor(text: $fullText)
}
}
func undoType(){
if let lastChar = fullText.last {
undoText.append(lastChar)
fullText = String(fullText.dropLast())
}
}
func redoType(){
if let lastChar = undoText.last {
undoText.removeLast()
fullText.append(lastChar)
}
}
}
Cannot reproduce the issue.
Works for me on macos 12.beta, xcode 13.beta, target ios 14.7 and macCatalyst 12. Tested on macOS 12 and iPhone ios 14.7.
import SwiftUI
@main
struct TestApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
struct ContentView: View {
@State var test = "My text \nhas a break line"
let test2 = "My text \nhas a break line"
var body: some View {
VStack (spacing: 30) {
Text(test)
Text(test.description)
Text("\(test)")
Text(test2)
}
}
}
yes you can, try this: (newVal will give it to you)
struct ContentView: View {
@State var theText = ""
var body: some View {
TextField("type something", text: $theText)
.onReceive(theText.publisher) { newVal in
// do your checks here on newVal
print("---> theText: \(theText) newVal: \(newVal) ")
}
}
}
you can also try this:
TextField("type something", text: $theText)
.onChange(of: theText) { newVal in
if let lastChar = newVal.last {
// do your check here on lastChar
print("--> last char: \(lastChar)")
}
}
here is another way:
TextField("type something", text: Binding(
get: { theText },
set: { newVal in
if let lastChar = newVal.last {
// do your checks here on lastChar
print("--> last char: \(lastChar) newVal: \(newVal) theText: \(theText)")
theText = newVal // if pass the checks
}
}))
you could try this:
struct ContentView: View {
var body: some View {
Text("keep calling a function").padding()
.onAppear {
callFunc()
}
}
func callFunc() {
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
print("-----> callFunc")
callFunc()
}
}
}
works well for me on macos 12.beta, xcode 13.beta, target ios 14.7 and macCatalyst 12.
Tested on macOS 12 and iPhone ios 14.7. You could try "Text(Date() + 60, style: .relative)"
struct ContentView: View {
var body: some View {
ScrollView {
Text(.init() + 60, style: .relative)
Text(.init() + 60, style: .date)
Text(.init() + 60, style: .time)
Text(.init() + 60, style: .timer)
Text(.init() + 60, style: .offset)
}
}
}
it seems to work for me, if you remove ".padding()" on the LazyVGrid.
could you try adding ".fixedSize()" to the HStack in ListView.
HStack {
..
}.fixedSize()
"...but I cannot see what.", we cannot see it either if you don't show us some code. "Are there any tips to investigate this further?, yes show us the code you are using.