Questions tagged [uihostingcontroller]
35 questions
19
votes
3 answers
UIHostingController should expand to fit contents
I have a custom UIViewControllerRepresentable (layout-related code shown below). This tries to replicate the native SwiftUI ScrollView, except it scrolls from the bottom except the top.
View hierarchy
view: UIView
|
\- scrollView: UIScrollView
|
…
![](../../users/profiles/2694431.webp)
Potassium Ion
- 1,687
- 16
- 37
7
votes
1 answer
Add SwiftUI View to an UITableViewCell contentView
I'm currently trying, to implement a UITableViewController in a UIViewControllerRepresentable, where the contents of the cells are SwiftUI Views again. I cannot use a SwiftUI List, because I want to add an UISearchController later on.
Because I want…
![](../../users/profiles/8162321.webp)
Josef Zoller
- 739
- 7
- 21
3
votes
1 answer
Delegate for SwiftUI View from Hosting View Controller
I add UIHostingViewController to my Storyboard and make class for this.
Load mySwiftUIView in controller init. Everything works good.
But i want to make hosting controller like delegate for mySwiftUIView because I want to handle button pressing in…
![](../../users/profiles/11266325.webp)
Ivan
- 33
- 2
3
votes
2 answers
How to Instantiate UIHostingController with CoreData?
As a long-time Obj-C dev (since iPhone OS 2) I decided that SwiftUI was the nudge to use Swift! ¯\(ツ)/¯
Thus, I am still trying to understand how a language can be so type-vague in code, and so type-pedantic in the compiler!!!
Pulling my hair out…
![](../../users/profiles/569604.webp)
Linasses
- 385
- 3
- 13
3
votes
2 answers
How to make a button that dismisses a view presented using UIHostingController/SwiftUI?
I have a fairly extensive project that I started with UIKit and now I've decided to use SwiftUI to make some simple form pages, but I need to make a button in SwiftUI to dismiss the current view which is presented with the following code:
func…
![](../../users/profiles/12001503.webp)
Watermamal
- 278
- 1
- 9
2
votes
1 answer
SwiftUI - How to access UIHostingController from SwiftUI
I have SwiftUI page, it's being navigated from UIKit view. I want to set a title to this page, what I'm doing is
// code of UIKit view
let controller = UIHostingController(rootView: SwiftUIView())
controller.title =…
![](../../users/profiles/13670083.webp)
Leo
- 23
- 3
2
votes
1 answer
SwiftUI: pass view information to UIKit
I have a UIKit and AppKit app, and I am displaying a SwiftUI view within it via UIHostingController / NSHostingController. The view has some buttons on it, and I want to pass back the tap event back to a UIKit/AppKit view controller to show…
![](../../users/profiles/145552.webp)
Z S
- 6,465
- 11
- 47
- 89
2
votes
0 answers
SwiftUI from UIHostingController: showing ActionSheet gives warning about detached view controller
I have created a SwiftUI view which I show in a MKMapView's annotation callout. I use UIHostingController to wrap the SwiftUI view, and use annotationView's detailCalloutAccessoryView property to set the view and display it. This works fine for the…
![](../../users/profiles/145552.webp)
Z S
- 6,465
- 11
- 47
- 89
2
votes
0 answers
UIHostingController view's transform gets out of sync when superview is translated before viewDidAppear
Given: UIHostingController hosted inside UIKit superview.
When: Superview transform modified before viewDidAppear. In this example moved 200pts down.
Then: Subsequent changes to superview transform will be out of sync. In this example I moved it…
![](../../users/profiles/13177324.webp)
John Rivera
- 21
- 3
2
votes
1 answer
NavigationView embedded in a UIHostingController has additional safe area insets
Anyone know how to deal with this? Seems as though when you have a UIHostingController with a NavigationView the following happens:
Notice the big grey tab bar safe area.
This is primarily a UIKit application. Were replacing on of our tabs in the…
![](../../users/profiles/9768031.webp)
Xaxxus
- 370
- 2
- 12
2
votes
1 answer
UITabBar containing SwiftUI View
I have the below series of controllers and views. However, when I use the navigation link on the MoreView it changes the tabBarItem.title value. For instance it will say more, but when the privacy policy button is clicked and the user is navigated…
![](../../users/profiles/5129990.webp)
Austin E
- 651
- 1
- 8
- 17
2
votes
1 answer
How to dismiss swiftUI from Viewcontroller?
In my an viewController I have this function
...{
let vc = UIHostingController(rootView: SwiftUIView())
present(vc, animated: true, completion: nil)
}
Which present the following SwiftUIView.
Q How to dismiss the SwiftUIView when…
![](../../users/profiles/1045446.webp)
RyanTCB
- 5,944
- 3
- 36
- 55
1
vote
1 answer
How to use Hosting Controller for SwiftUI in existing Storyboard Tab Bar Controller?
I'm trying to use a Hosting Controller to include a SwiftUI View in an existing Storyboard Tab Bar Controller. I already connected a Hosting View Controller to the Tab Bar Controller on Storyboard using the Relationship Segue. Below is what I…
![](../../users/profiles/13395239.webp)
Ryan Kanno
- 65
- 7
1
vote
0 answers
Can UISwipeGestureRecognizer work for view in UIHostingController?
As per answer in https://stackoverflow.com/a/64726641/3286489, I can perform a swipe down to dismiss a fullscreen ViewController using UISwipeGestureRecognizer.
However, when I transfer the same code to UIHostingController as below, it doesn't work…
![](../../users/profiles/3286489.webp)
Elye
- 30,821
- 26
- 115
- 272
1
vote
1 answer
How to set UIHostingController's background color to clear?
I need to be able to see through my SwiftUI Views as well as the UIHosting Controller presenting them in order to see a background image underneath them. The code below still shows a white rectangle under my SwiftUI View. Paul Hudson says to use…
![](../../users/profiles/4625622.webp)
GarySabo
- 4,076
- 5
- 27
- 76