Post

Replies

Boosts

Views

Activity

Reply to NavigationLInk
how can I create the loop to create the navigation links in body? Have you read my answer? you may need to use onAppear {...} If you cannot apply generic code example into your actual code, please include enough code in your opening post. (Please show an accurate code, no typo in it please.) import SwiftUI struct MyListView: View { let category: CategoryModel @ObservedObject var store = MyStore() // <- I guess you should use singleton for `MyStore`, but you have not shown its detail... var body: some View { List(store.categories.indices, id:\.self) { categoryIndex in let category = store.categories[categoryIndex] NavigationLink(destination: CategoryView(categoryId: category.id) ) { CategoryRow(category: category) } } .onAppear { self.store.getData(categoryId: category.id) } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Sep ’21
Reply to NavigationLInk
MyListView is being called I do not understand what you mean by being called, but I guess you may be doing something in init or body, which may be executed at any time (which are hard to predict) by the runtime of SwiftUI. If you want to do something on appearance of a view, you may need to use onAppear {...}: (Or task {...} if you can target your app to iOS 15+.) struct MyListView: View { let category: Category var body: some View { listViewContent() .onAppear { print("onAppear called") //Do API calls here... } } @ViewBuilder private func listViewContent() -> some View { Text("listViewContent...") //... } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Sep ’21
Reply to Init or body ?
but need to call the method inside the body.  Can you explain why you think so? In almost all cases, you have no need to (and should not) do something in body. You may be mistaking something. Have you tried onAppear {...} ?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Sep ’21
Reply to Can't interpolate a Bool in SwiftUI Text?
When you write a String Interpolation directly inside Text.init(_:), it is interpreted as a LocalizedStringKey, not String. So, LocalizedStringKey.StringInterpolation works. You should better also read this: SE-0228 Fix ExpressibleByStringInterpolation If you want to make a String Interpolation of String type, you can write something like this: Text("Hello. \(test)" as String) Or Text(verbatim: "Hello. \(test)") (In both samples, "Hello. 〜" would not be localized.) To make it localizable, you may need to write: Text("Hello. \(test.description)") Or Text("Hello. \(String(test))") (To localize true or false, you may need a little more effort.)
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Sep ’21
Reply to Autocomplete in xCode 13 RC
I tried with a vanilla SwiftUI project with the released version of Xcode 13 (same build number 13A233), and typed Picker after removing Text..., I got the expected candidates starting with the initializers of Picker. But using Xcode 13 till now, there were some other cases autocomplete did not work. So I guess Picker is not the key of this malfunctioning but your Xcode is not ready for autocomplete. One possibility is you just need to wait, or some errors in other parts of your code may affecting. Can you try with a brand-new project again?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Sep ’21
Reply to Collapse button NavigationView SideBar SwiftUI
If you do want SwiftUI only solution, you should not have included the tag UIKit. When the tags or the terms may not be appropriate enough, you should better try to explain your issue more precisely. Including codes and/or images will help avoiding confusion of readers. What I want to really achieve is the sidebar that is used in the iPad Settings app I could not find a simple way to hide Collapse button on navigation bar. Also, as far as I checked the UI design of Settings app of iOS 14 & 15 The UI does not change whether in portrait or in landscape Each row in the list does not have a disclosure indicator (⟩) So, I guess, the Settings app is not constructed simply using the ColumnNavigationViewStyle and NavigationLink. You may need to do it all by yourself. A little bit simplified example: struct ContentView: View { @State var secondViewTitle: String? let rows = ["Hello", "World"] var body: some View { HStack { NavigationView { List { Section { ForEach(rows, id: \.self) { row in Button(action: { if self.secondViewTitle == row { self.secondViewTitle = nil } else { self.secondViewTitle = row } }, label: { HStack { Text(row) .padding() Spacer() } }) .background(self.secondViewTitle == row ? Color.accentColor : Color.white) .listRowInsets(EdgeInsets()) } .foregroundColor(Color.primary) } } .listStyle(InsetGroupedListStyle()) .navigationTitle("Test") } .navigationViewStyle(StackNavigationViewStyle()) .frame(width: 360) SecondView(title: secondViewTitle) .frame(maxWidth: .infinity) } } } struct SecondView: View { let title: String? var body: some View { Text("\(title ?? "")") } }
Topic: UI Frameworks SubTopic: UIKit Tags:
Sep ’21
Reply to "onTapGesture" interferes with segmented picker
Can you explain what you mean by I want to do sth when the picker is taped? It may be preferable to describe what result you want on what sort of user action/event.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Sep ’21
Reply to How can I use the searchable feature for my row data in SwiftUI?
Please show the complete code which shows your data. It is very hard to show something under the fragment of code.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Sep ’21
Reply to NavigationLInk
how can I create the loop to create the navigation links in body? Have you read my answer? you may need to use onAppear {...} If you cannot apply generic code example into your actual code, please include enough code in your opening post. (Please show an accurate code, no typo in it please.) import SwiftUI struct MyListView: View { let category: CategoryModel @ObservedObject var store = MyStore() // <- I guess you should use singleton for `MyStore`, but you have not shown its detail... var body: some View { List(store.categories.indices, id:\.self) { categoryIndex in let category = store.categories[categoryIndex] NavigationLink(destination: CategoryView(categoryId: category.id) ) { CategoryRow(category: category) } } .onAppear { self.store.getData(categoryId: category.id) } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Sep ’21
Reply to Side by side Picker wheels failing in iOS 15
but the touch area seems to overlap. Seems to be the same issue as this thread: Limit width of wheel style picker on iOS Have you tried using .compositingGroup() as shown in it?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Sep ’21
Reply to NavigationLInk
MyListView is being called I do not understand what you mean by being called, but I guess you may be doing something in init or body, which may be executed at any time (which are hard to predict) by the runtime of SwiftUI. If you want to do something on appearance of a view, you may need to use onAppear {...}: (Or task {...} if you can target your app to iOS 15+.) struct MyListView: View { let category: Category var body: some View { listViewContent() .onAppear { print("onAppear called") //Do API calls here... } } @ViewBuilder private func listViewContent() -> some View { Text("listViewContent...") //... } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Sep ’21
Reply to Open View using Button
I do not understand what you mean by with button, the chosen View will open under .sheet or .fullScreenCover. Can you show the complete code which can reproduce the issue?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Sep ’21
Reply to Init or body ?
but need to call the method inside the body.  Can you explain why you think so? In almost all cases, you have no need to (and should not) do something in body. You may be mistaking something. Have you tried onAppear {...} ?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Sep ’21
Reply to Xcode 13 app connect upload fail.
You cannot use beta versions of tools to submit apps to the App Store. Better get the released version of Xcode and try again.
Replies
Boosts
Views
Activity
Sep ’21
Reply to Can't interpolate a Bool in SwiftUI Text?
When you write a String Interpolation directly inside Text.init(_:), it is interpreted as a LocalizedStringKey, not String. So, LocalizedStringKey.StringInterpolation works. You should better also read this: SE-0228 Fix ExpressibleByStringInterpolation If you want to make a String Interpolation of String type, you can write something like this: Text("Hello. \(test)" as String) Or Text(verbatim: "Hello. \(test)") (In both samples, "Hello. 〜" would not be localized.) To make it localizable, you may need to write: Text("Hello. \(test.description)") Or Text("Hello. \(String(test))") (To localize true or false, you may need a little more effort.)
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Sep ’21
Reply to [iOS 15]The tableView(_:numberOfRowsInSection:) is called before the numberOfSections(in tableView: UITableView)
How do you set the dataSource of the table view? On the storyboard? Or setting it in viewDidLoad() with code?
Replies
Boosts
Views
Activity
Sep ’21
Reply to Xcode 13 - warning: Could not read serialized diagnostics file: error("Invalid diagnostics signature")
Can you find and show the minimized steps to reproduce the issue?
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Sep ’21
Reply to Crash in UITableview cellforrow in iOS 15 beta
It is hard to find the cause of crashes even when properly formatted crash logs given. Can you show the crash log properly formatted and your code?
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Sep ’21
Reply to Autocomplete in xCode 13 RC
I tried with a vanilla SwiftUI project with the released version of Xcode 13 (same build number 13A233), and typed Picker after removing Text..., I got the expected candidates starting with the initializers of Picker. But using Xcode 13 till now, there were some other cases autocomplete did not work. So I guess Picker is not the key of this malfunctioning but your Xcode is not ready for autocomplete. One possibility is you just need to wait, or some errors in other parts of your code may affecting. Can you try with a brand-new project again?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Sep ’21
Reply to Downgrade to xcode 12.5
You can download Xcode 12.5.1 (or 12.5 if your Xamarin thing requires) from More Downloads pages. You can expand it and move Xcode (Xcode.app) to Applications folder, which will replace your current Xcode 13.
Replies
Boosts
Views
Activity
Sep ’21
Reply to Collapse button NavigationView SideBar SwiftUI
If you do want SwiftUI only solution, you should not have included the tag UIKit. When the tags or the terms may not be appropriate enough, you should better try to explain your issue more precisely. Including codes and/or images will help avoiding confusion of readers. What I want to really achieve is the sidebar that is used in the iPad Settings app I could not find a simple way to hide Collapse button on navigation bar. Also, as far as I checked the UI design of Settings app of iOS 14 & 15 The UI does not change whether in portrait or in landscape Each row in the list does not have a disclosure indicator (⟩) So, I guess, the Settings app is not constructed simply using the ColumnNavigationViewStyle and NavigationLink. You may need to do it all by yourself. A little bit simplified example: struct ContentView: View { @State var secondViewTitle: String? let rows = ["Hello", "World"] var body: some View { HStack { NavigationView { List { Section { ForEach(rows, id: \.self) { row in Button(action: { if self.secondViewTitle == row { self.secondViewTitle = nil } else { self.secondViewTitle = row } }, label: { HStack { Text(row) .padding() Spacer() } }) .background(self.secondViewTitle == row ? Color.accentColor : Color.white) .listRowInsets(EdgeInsets()) } .foregroundColor(Color.primary) } } .listStyle(InsetGroupedListStyle()) .navigationTitle("Test") } .navigationViewStyle(StackNavigationViewStyle()) .frame(width: 360) SecondView(title: secondViewTitle) .frame(maxWidth: .infinity) } } } struct SecondView: View { let title: String? var body: some View { Text("\(title ?? "")") } }
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
Boosts
Views
Activity
Sep ’21