Post

Replies

Boosts

Views

Activity

Custom view doesn't load properly when presented as a modal sheet
Hello! I am making my first SwiftUI application, and I encountered an annoying problem, to which I can't find a solution. So, I have a made a custom class, which is basically listing out items in a List view, but these items are made up of other custom views as well. Users can tap on these items, to add them or remove them from an array, which is present as an environment object. Now, when I add this custom view as a tab view to my application, it appears as it should, no problem whatsoever. I can tap on one of the items, a chechmark gets added next to it, and when I look at my other view, which lists out the items I have selected, it works great, the selected items are shown. But if I add this view to a sheet, which shows on a button press, some of the view elements don't show up. I can still select them, and the other view will display the selected items, but it's like half of the custom item views are left off the screen. Interestingly enough, if I try to dismiss the modal sheet by dragging it down, the rest of the custom item views show up, and it works again. Unfortunately I can't provide images but imagine this: the custom view contains a list view, which lists out customItemView items. These customItemView items contain an image and some text. When I try to load the sheet, the images are shown, but not the text. The classes in question: This contains the calling of the modal sheet on button press: struct CurrenciesTabView: View {   @EnvironmentObject var watchedCurrencies: CurrencyContainer   @State var isSelectorOpen = false       var body: some View {     VStack() {       CurrencyList(selectedCurrencies: watchedCurrencies)       Button("Szerkesztés"){         isSelectorOpen = true       }       .sheet(isPresented: $isSelectorOpen){         CurrencySelectorView().environmentObject(watchedCurrencies)       }       .foregroundColor(.white).background(RoundedRectangle(cornerRadius: 50.0).frame(width: 120, height: 40).foregroundColor(.blue)).padding()     }   } } This is the custom view, that's put on the sheet (which works on a tab view, but not on the sheet): struct CurrencySelectorView: View {   @EnvironmentObject var selectedCurrencies: CurrencyContainer       var body: some View {     List(Currency.Symbol.allCases, id:\.self) { symbol in       ItemView(symbol: symbol.rawValue)     }   }       func appendToList(currency: Currency) - Void {     selectedCurrencies.appendCurrency(currency: currency)   }       func removeFromList(currency: Currency) - Void {     selectedCurrencies.removeCurrency(at: selectedCurrencies.getCurrencies().firstIndex(of: currency)!)   } } extension CurrencySelectorView {   struct ItemView: View {     let symbol: String     @EnvironmentObject var selectedCurrencies: CurrencyContainer           var body: some View {       HStack {         CurrencyItemView(symbol: symbol)         if selectedCurrencies.contains(symbol: symbol) {           Image(systemName: "checkmark")         }       }.onTapGesture {         if selectedCurrencies.contains(symbol: symbol) {           selectedCurrencies.removeCurrency(symbol: symbol)         } else {           selectedCurrencies.appendCurrency(currency: Currency(symbol: Currency.Symbol.init(rawValue: symbol)!))         }       }     }           init(symbol: String) {       self.symbol = symbol     }   } } These are the items, that are listed out on the custom view (the Image views are shown, but not the Text views on the openin of the sheet): struct CurrencyItemView: View {   let imageName: String   let symbol: String   let value: Double   let base: String       var body: some View {     HStack() {       Image(imageName)         .resizable()         .aspectRatio(contentMode: .fit)         .frame(height: 50)       HStack() {         Text(symbol)       }       Spacer()     }.contentShape(Rectangle())   }       init(imageName: String, symbol: String, value: Double, base: String) {     self.imageName = imageName     self.symbol = symbol     self.value = value     self.base = base   }       init(symbol: String) {     self.imageName = symbol     self.symbol = symbol     self.value = 0.0     self.base = ""   } } The environmentObject is in the enviroment, and as I said, it works as it should, the very same array is correctly shared between the views (the CurrencyContainer object is basically holding an array, with a couple of added methods). Can you help me out in resolving this issue? It's been driving me mad for days now, and I think the app would look cleaner, if this view was presented on a modal sheet instead of a tab view. Thanks in advance!
2
0
815
May ’21
Cannot preview in this file - Failed to update preview
Hello! I've been trying to develop my first Swift and iOS application, but I'm trying to take one step at a time. I installed xCode and created my first SwiftUI project, and I did nothing with it, didn't modify it, it's the plain Hello World application. Now, the first thing I wanted to do was to preview the app on my own device, so I followed the steps to that. But when I try to preview the app on my phone, I get the error in the title. This is so strange, cause both my phone and my mac are on the latest softwares, and it's really just the plain starting project, nothing else added. I've seen this problem all over the forums and StackOverflow, but I had no luck in fixing the problem with those solutions so far. I don't really know what to include, so here is the diagnostic message: RemoteHumanReadableError: Failed to update preview. Error encountered when sending 'display' message to agent. ================================== | RemoteHumanReadableError |   | LoadingError: failed to load library at path "/private/var/mobile/Containers/Data/Application/E7DA406F-45A9-4A13-B424-EEC934C6FA04//tmp/1433213E-46DF-4CA8-A16A-CCDBA9545F1C-ContentView.2.preview-thunk.dylib": Optional(dlopen(/private/var/mobile/Containers/Data/Application/E7DA406F-45A9-4A13-B424-EEC934C6FA04/tmp/1433213E-46DF-4CA8-A16A-CCDBA9545F1C-ContentView.2.preview-thunk.dylib, 2): no suitable image found. Did find: |  /private/var/mobile/Containers/Data/Application/E7DA406F-45A9-4A13-B424-EEC934C6FA04/tmp/1433213E-46DF-4CA8-A16A-CCDBA9545F1C-ContentView.2.preview-thunk.dylib: code signature invalid for '/private/var/mobile/Containers/Data/Application/E7DA406F-45A9-4A13-B424-EEC934C6FA04/tmp/1433213E-46DF-4CA8-A16A-CCDBA9545F1C-ContentView.2.preview-thunk.dylib' | ) If you need anything else, please let me know. Thank you in advance for all your help, it's truly appreciated, because I've been going mad about this issue for a couple of days now.
0
0
867
Feb ’21