Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uikit Crashes to iPad #2

Open
myanalysis opened this issue Jun 22, 2021 · 1 comment
Open

Uikit Crashes to iPad #2

myanalysis opened this issue Jun 22, 2021 · 1 comment

Comments

@myanalysis
Copy link

code does not work when using iPad with the UIkit.

Thread 1: “UIPopoverPresentationController (<UIPopoverPresentationController: 0x147d52ff0>) should have a non-nil sourceView or barButtonItem set before the presentation occurs.”

thanks.

@ketyung
Copy link
Owner

ketyung commented Jun 22, 2021

HI , which part of the code u use with a UIPopoverPresentationController to present?

Are you talking about you're using a UIHostingController to wrap the SwiftUI views and then to be presented by a UIPopoverPresentationController ? Btw, this is not anything involves the SwiftUI codes, I think you should look into your own code how you implement a UIPopoverPresentationController ,

Commonly, a UIPopoverPresentationController is presented with the following codes :

let contentView = ContentView() // contentView is a swiftUI view
let vc = UIHostingController(rootView : contentView)
vc.preferredContentSize = CGSize(width: 300, height: 300)
vc.modalPresentationStyle = .popover

if let popover: UIPopoverPresentationController = vc.popoverPresentationController{
popover.delegate = self
popover.sourceView = self.view
popover.barButtonItem = myBarButtonItem // your bar button item created somewhere else
present(vc, animated: true, completion:nil)
}

Hope it helps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants