3

In the Integrating SwiftUI WWDC video it shows the example of using an IBSegueAction to transition to a SwiftUI view, is it possible to do this programmatically?

I have a SwiftUI app with a UIKit TableViewController (via UIViewControllerRepresentable), it's this table I'm looking to segue from to another SwiftUI view.

Essentially: SwiftUI TabView -> UIKit TableView -> SwiftUI View

Or will I need to setup storyboard to achieve this segue?

Cœur
  • 37,241
  • 25
  • 195
  • 267
jsrgnt
  • 154
  • 5
  • You can't, see also here: https://stackoverflow.com/questions/36216582/create-and-perform-segue-without-storyboards – koen Oct 02 '19 at 12:04
  • I think you can push using NavigationLink, put your cell code in NavigationLink – Jayraj Vala Oct 02 '19 at 12:24
  • 1
    Segues are deeply integrated with storyboards. By deeply, I mean to say you *cannot* simply create one and use it programmatically - you *need* a storyboard. Now, if what you want is to push a `UITableView` onto a SwiftUI stack and from there push a SwiftUI view... that *may* be possible. Just not using a segue. –  Oct 02 '19 at 23:13
  • @dfd I thought this would be the case. Adding a UITableView to the SWiftUI stack was actually pretty straightforward (using UIViewControllerRepresentable) but it's now going from UITableView to another SwiftUI View that look like it may not be possible, without the use of a storyboard segue. – jsrgnt Oct 03 '19 at 07:31
  • I had something close to that - I used a UITableView/UINavigationController in my SwiftUI app. (Don't ask why, it's related to the various weaknesses of the alternative, a list/NavigationView.) I was able to actually communicate using Notifications (again don't ask but I never got straight Combine to work either, in fact one person here on SO suggested using a 'wrapper" View because, well, everything *isn't* a View in SwiftUI). In the end I went with a UIKit app. SwiftUI just isn't robust enough.... –  Oct 03 '19 at 09:41

2 Answers2

0

Create a hidden Navigation Link with the Bool.

NavigationLink(destination: NextView(), isActive: self.isShowNext) {
    Text("")
}.hidden()
Dc7
  • 1,405
  • 1
  • 10
  • 16
-1

It's theoretically possible in your Coordinator for your UIViewRepresentable to push a UIHostingController with your SwiftUI view if it's navigationController property is set:

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
    let view = SomeView()
    navigationController?.pushViewController(UIHostingController(root: view))
}

But I think you will find it easiest to use UIKit up until the point where you don't think you need it again. So instead of:

TabView => NavigationView => wrapped UITableViewController => some SwiftUI View

it should be:

UITabBarController => UINavigationController => UITableViewController => UIHostController(root: SwiftUIView)

But why don't you simply want to use List?

TabView => NavigationView => List => SwiftUIView

Procrastin8
  • 4,193
  • 12
  • 25