Post

Replies

Boosts

Views

Activity

Reply to open a New View from a item in a contextual menu
Bonjour Thank you again for your help That was easier than expected... After 2 months of hard reading on iOS, swiftui, I think my brain got it and I starting to believe that iOS dev is not unreachable So the solution for me: use a popover, a sheet view or simply a navigationlink When you don't know, you don't know... we have all been newbies... example: inline-code ToolbarItem(placement: .navigationBarTrailing) { Menu { NavigationLink(destination: MainView() .navigationBarBackButtonHidden(true) ) { Label("Accueil", systemImage: "homekit") } /// rest of the code Merci beaucoup for your help
Aug ’23
Reply to open a New View from a item in a contextual menu
Ok thanks I think we are not far from the result I expected this is what I want to achieve? when the app start it opens a MainView() here is the MainView code import SwiftUI struct MainView: View { var body: some View { NavigationView { VStack(spacing: 10) { Spacer() Text("Example en panne") .font(.system(size: 40)) NavigationLink(destination: View1() .navigationBarBackButtonHidden(true) ) { VStack { Image(systemName: "book") .resizable() .aspectRatio(contentMode: .fit) .frame(width: 140, height: 140) Text("Ma vue 1") .font(.headline) } } Spacer() } } } } struct MainView_Previews: PreviewProvider { static var previews: some View { MainView() } } from the MainView I call View1 or View2 Here is the code for View1 import SwiftUI struct View1: View { @State private var selectedTab = 0 @State private var showCopyright = false var body: some View { if showCopyright { // MUST BE INSIDE body MainView() // Or whatever you call it ; it could also simply be a Text() } NavigationView { TabView(selection: $selectedTab) { maPage1() .tabItem { Image(systemName: "book") Text("Page 1") } .tag(0) maPage2() .tabItem { Image(systemName: "heart") Text("Page 2") } .tag(1) } //.navigationBarTitleDisplayMode(.inline) .navigationBarTitle("truc") .toolbar { ToolbarItem(placement: .navigationBarTrailing) { Menu { Button(action: { showCopyright = true // Show modal text for copyright }) { Label("Copyright", systemImage: "text.book.closed") } Button(action: { // Go to HelpView }) { Label("HelpView", systemImage: "questionmark.circle") } } label: { Image(systemName: "house") } } } } } } and the CopyrightView is as such: import SwiftUI struct CopyrightView: View { var body: some View { Text("Here is the Copyright text en some details about the App") } } struct CopyrightView_Previews: PreviewProvider { static var previews: some View { CopyrightView() } } nothing fancy the behavior I want: when the app opens, It shows Mainview when I click on the icon for View1 it opens View1 till now all is well from View1 I want to click on the "house" icon in the contextual Menu to open MainView the problem : from the contextual Menu, it opens Mainview() now but but only on half of the screen, the other part of the screen still show View1 Before I had nothing when I clicked on the icon for MainView in the contextual menu, now things get better I hope I explain better Thanks
Jul ’23
Reply to open a New View from a item in a contextual menu
I did exactly as you indicated without success The code is still wrong? import SwiftUI struct Bible: View { @State private var selectedTab = 0 @State private var showCopyright = false var body: some View { NavigationView { TabView(selection: $selectedTab) { View1() .tabItem { Image(systemName: "book") Text("La vue 1") } .tag(0) View2() .tabItem { Image(systemName: "heart") Text("La vue 2") } .tag(1) } //.navigationBarTitleDisplayMode(.inline) .navigationBarTitle("Ma page") .toolbar { ToolbarItem(placement: .navigationBarTrailing) { Menu { NavigationLink(destination:MainView()){ Label("MainView", systemImage: "house") } Button(action: { showCopyright = true // Show modal text for copyright }) { Label("Copyright", systemImage: "text.book.closed") } Button(action: { NavigationLink(destination:HelpView()){ Label("Help", systemImage: "questionmark.circle") } }) { } } label: { Image(systemName: "house") } } } } } if showCopyright { CopyrightView() // Or whatever you call it ; it could also simply be a Text() } }
Jul ’23
Reply to open a New View from a item in a contextual menu
Bonjour Here is my code in context import SwiftUI struct Bible: View { @State private var selectedTab = 0 var body: some View { NavigationView { TabView(selection: $selectedTab) { View1() .tabItem { Image(systemName: "book") Text("La vue 1") } .tag(0) View2() .tabItem { Image(systemName: "heart") Text("La vue 2") } .tag(1) } //.navigationBarTitleDisplayMode(.inline) .navigationBarTitle("Ma page") .toolbar { ToolbarItem(placement: .navigationBarTrailing) { Menu { NavigationLink(destination:MainView()){ Label("MainView", systemImage: "house") } Button(action: { CopyrightView() }) { Label("Copyright", systemImage: "text.book.closed") } Button(action: { NavigationLink(destination:HelpView()){ Label("Help", systemImage: "questionmark.circle") } }) { } } label: { Image(systemName: "house") } } } } } } I try 3 different way to call the view, MainView(), CopyrightView() and HelpView() without success I use a tab view to call View1 and View 2 The menu is shown in View1 and View2 and opens well, but it is not possible to open the 3 views from there thank you for your help blessings David
Jul ’23
Reply to Error Type '() -> ()' cannot conform to 'StringProtocol'
Sorry I am really new in swift and Xcode... I am learning I am a php and android developper Please forgive me when I put only .searchable(text: $searchText) the code works well, all the titles are there, but the search bar do not seems to call or change the function fetchCantiqueTitles(searchText: String) the error is shown for this line: .navigationTitle("Hymnes et Louanges") if I remove this line, the error will still appear but for VStack { infos on this code, when a item is clicked, the new view destination: hymnesetlouangesafficher(cantique: cantique) is call I pass the item id to this view so what I want to do: when the view starts, the function fetchCantiqueTitles(searchText: String) is called all the titles ar shown What I want: when something is typed in the search bar, this entry is sent to the function fetchCantiqueTitles(searchText: String) only the titles containing the entry are shown let query = "SELECT ref, titre FROM cantiques WHERE titre LIKE '%(searchText)%'" there is a better way to do this? Maybe my code is a strange mess English is my second language I tried to explain my situation the best I could
Mar ’23