|
Whenever i try to select 5 (String) in the content view the app crashes. But if i select 1 then it works. I want to display a VStack of 5 questions when 5 is selected in the picker in content View. The code in Play strut(2nd view or the question display View)
|
|
|
|
like when I try to open the navigation link button from the content view, it doesn't open and hangs and many times of strings(numbers too which is kinda greek to be) come in the log. and I have to rebuild it, even then it persist but then again if I do it by selecting userQ is 1 it shows me that single view as intended. |
|
That doesn't really help, unfortunately. Please copy and paste in whatever error you get in the debugger. Also, it would probably be useful to see your |
|
Ok. this is my content View:
My Play view:
(I tried calling the view from a separte file but still didnt work.) The view that should display multiple lines.
Questions Struct:
|
|
log: 2021-08-09 23:35:32.883998+0530 Tables[4731:88372] [Assert] UIScrollView does not support multiple observers implementing _observeScrollView:willEndDraggingWithVelocity:targetContentOffset:unclampedOriginalTarget:. Scroll view <_TtC7SwiftUIP33_BFB370BA5F1BADDC9D83021565761A4925UpdateCoalescingTableView: 0x7fedcd047800; baseClass = UITableView; frame = (0 0; 428 926); clipsToBounds = YES; gestureRecognizers = <NSArray: 0x6000030c0d50>; layer = <CALayer: 0x600003e1ffc0>; contentOffset: {0, -239}; contentSize: {428, 220}; adjustedContentInset: {239, 0, 34, 0}; dataSource: <_TtGC7SwiftUIP13$7fff56921d2819ListCoreCoordinatorGVS_20SystemListDataSourceOs5Never_GOS_19SelectionManagerBoxS2_: 0x7fedcc617e60>>, new observer <_TtGC7SwiftUI41StyleContextSplitViewNavigationControllerVS19SidebarStyleContext: 0x7fedcf83e400>, removing old observer <_TtGC7SwiftUI41StyleContextSplitViewNavigationControllerVS19SidebarStyleContext: 0x7fedd004c800> 2021-08-09 23:35:32.884509+0530 Tables[4731:88372] [Assert] UIScrollView does not support multiple observers implementing _observeScrollView:willEndDraggingWithVelocity:targetContentOffset:unclampedOriginalTarget:. Scroll view <_TtC7SwiftUIP33_BFB370BA5F1BADDC9D83021565761A4925UpdateCoalescingTableView: 0x7fedcd047800; baseClass = UITableView; frame = (0 0; 428 926); clipsToBounds = YES; gestureRecognizers = <NSArray: 0x6000030c0d50>; layer = <CALayer: 0x600003e1ffc0>; contentOffset: {0, -239}; contentSize: {428, 220}; adjustedContentInset: {239, 0, 34, 0}; dataSource: <_TtGC7SwiftUIP13$7fff56921d2819ListCoreCoordinatorGVS_20SystemListDataSourceOs5Never_GOS19SelectionManagerBoxS2: 0x7fedcc617e60>>, new observer <_TtGC7SwiftUI41StyleContextSplitViewNavigationControllerVS19SidebarStyleContext: 0x7fedd004c800>, removing old observer <_TtGC7SwiftUI41StyleContextSplitViewNavigationControllerVS19SidebarStyleContext: 0x7fedcf83e400> If i removeve navigation View from play view this log doesnt come, but even then the app just hangs, it doesnt even move to the play view from content view. |
|
You definitely should remove the The hang you are experiencing is because you are mutating state during a view update. You should not do that. The offending code is here:
is a bad idea. It apparently won't cause problems when it's just done once, which is why it works when you select "1", but it will if it happens multiple times, which is why it freaks out when you select "5" or "10" or "15". You can see that it works correctly if, for instance, you use this instead:
This does not mutate your state, so it doesn't cause a problem when updating the view. You need to rethink your model and how you are generating the questions to avoid this issue. |
|
Thanks a lot, the hanging problem was solved, so i did try to change my approach. To the code below:
I am not getting the actual answer according to what the question right is displayed. I think it is becasue its taking two instances. what to do if i want to get the actual Ans accordingly ? |
TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!
Sponsor Hacking with Swift and reach the world's largest Swift community!
This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.