Hi Jim Dovey, You are right. I didn't realize that List can already let me scroll for the content more than one screen. The ForEach solution works for me because it seems to support more than 10 items inside.Thank you!struct ContentView: View {
var body: some View {
List {
ForEach(1 ... 100, id: \.self ) {
x in
VStack {
Text("dfsf")
Text("sfsdfj")
}
}
}.padding(10)
}
}
Post
Replies
Boosts
Views
Activity
Hi Claude31,My original purpose is to display a long list of content without realizing List can already scroll. Now the problem is resolved. Thank you!
Hi KMT and Jim Dovey,I submitted a bug report in https://feedbackassistant.apple.com/feedback/7496464Not get getting response. For now I am more frequently using online document.Thank you!
A solution is figured out: I don't need to use the viewWillTransition event. Below is the code I wrote:import SwiftUI
import GoogleMobileAds
import UIKit
struct ContentView: View {
var body: some View {
VStack(alignment: .leading) {
AdView().frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: 300).border(Color.red, width: 5)
}
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity)
.border(Color.yellow, width: 2)
}
}
struct AdView : UIViewRepresentable {
@State private var banner: GADBannerView = GADBannerView(adSize: kGADAdSizeBanner)
func makeUIView(context: UIViewRepresentableContext<AdView>) -> GADBannerView {
banner.adUnitID = "ca-app-pub-3940256099942544/2934735716"
banner.rootViewController = UIApplication.shared.windows.first?.rootViewController
banner.load(GADRequest())
return banner
}
func updateUIView(_ uiView: GADBannerView, context: UIViewRepresentableContext<AdView>) {
banner.adSize = kGADAdSizeBanner
banner.load(GADRequest())
}
}When the device (in simulator) rotates, the AD size changed.
I am glad that this time seems I did something useful for the community 🙂
Thank you jonsteinmetz! I encountered similar issue and your solution works for me.
If your app has NavigationView, you can check whether it have the same situation as this threadhttps://forums.developer.apple.com/thread/119691The display of NavigationView will be broken if not configured properly.
I encountered the same situation when running app in simulator. I found that it is only for simulator with iOS 13.3. Below are my test resultsiPhone 8 simulator with iOS 13.3 --- there is issue: NavigationLink no long work after navigating backiPhone 8 simulator with iOS 13.2.2 --- OKa physical iPhone with iOS 13.3 --- OKluckly seems this is a simulator only issue and it is only for iOS 13.3. I hope it can be fixed in next iOS version.
Hi Claude31,Thank you! Even though it seem counter intuitive to me to make an empty view for the navigationlink itself, and then add a button to trigger it, it works for me.
I found a work-around: use .sheet modifier instead of .alert modifier, such that I can use the onDismiss closure to toggle the state variable for navigation link after message is dismissed.Reference: htt ps:// swiftwithmajid.com/2019/07/24/alerts-actionsheets-modals-and-popovers-in-swiftui/However, I feel that this solution is pretty complicated, and wondering whether there is any better idea.
Thank you Claude31!The code I initially posted was modified from some complicated original code to present the issue in a simple way, and I didn't put it back to test before posting. Thank you for checking this and correcting it. For other reader's convenience, I pasted your code to a single view project and update it to make sure it works. I got:struct ContentView: View {
@State var showDetail: Bool = false
@State private var displayPopupMessage: Bool = false
var body: some View {
NavigationView {
VStack {
NavigationLink(destination: DetailView(), isActive: self.$showDetail) { EmptyView() }
Button(action: {
self.displayPopupMessage = true
}) {Text("Alert and Navigate")}
.alert(isPresented: $displayPopupMessage){
Alert(title: Text("Warning"), message: Text("This is a test"), dismissButton:
.default(Text("OK"), action: {self.showDetail = true})
)
}
}
}
}
}
struct DetailView :View {
var body: some View {Text("details ...")}
}Above code was tested in a project to be fully working. I added the NavigationView to make sure it works in a separate project.This solution confirms that each section of code should only make one popup message or navigation change.Thank you!
Thank you! BabyJ.
Thank you Claude31!
Hi Claude31,
The stackoverflow link shows a way that needs to inject hosting window in root ContentWindow from AppDelegate or SceneDelegate. However, in the new Multiplatform App template, there is no AppDelegate/SceneDelegate by default. Seems they are being deprecated. Is there a way to do it without AppDelegate/SceneDelegate?
Thank you!
Just an update of the status, for now I set the "Enable Multiple Windows" in info.plist to false, such that I don't need to get the scene for now. The original reason I want to get the scene object is because I am trying to use Google Admob in an iOS app for iPad. Since iPad by default supports multiple windows, Admob is asking me to input scene. After disabling multiple windows, AdMob is no longer asing for it.
Google AdMob link is not allowed to be posted in the forum, so I cannot include it.