Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
SwiftUI_List_Segue
import SwiftUI
final class TextModel: ObservableObject {
@Published var roomIndex = Array<String>()
}
struct ContentView: View {
@State private var tag : Int?
@State private var view: AnyView?
@State private var room = ""
@State private var c: ContentView2?
@ObservedObject var textModel = TextModel()
var body: some View {
NavigationView {
VStack {
TextField("Room", text: $room,
onCommit: {
textModel.roomIndex.append(room)
self.c = ContentView2(viewModel: textModel)
self.tag = 0
})
.textFieldStyle(RoundedBorderTextFieldStyle())
.padding()
Spacer()
NavigationLink(destination: AnyView(c), tag: self.tag ?? 0, selection: $tag) {
EmptyView()
}
}
.navigationBarTitle("", displayMode: .inline)
.onDisappear {
room = ""
}
}
}
}
struct ContentView2: View {
@State private var tag : Int?
@State private var view: AnyView?
@State private var t: TextModel?
@ObservedObject var viewModel: TextModel
var body: some View {
List(self.viewModel.roomIndex.indices, id: \.self) { index in
NavigationLink(destination: Text (self.viewModel.roomIndex[index])) { Text(self.viewModel.roomIndex[index]) }
}
}
}
@daisukenagata

This comment has been minimized.

Copy link
Owner Author

@daisukenagata daisukenagata commented Oct 23, 2020

LISTSAMPLE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment