Код: Выделить всё
struct NavStack: View {
@AppStorage("userid") var userid: Int = 0
@State var memes = [MemeModel]()
@State var path = NavigationPath()
var body: some View {
NavigationStack(path: $path){
ScrollView(.vertical, showsIndicators: false){
LazyVStack(spacing: 100){
ForEach($memes, id: \.memeid){ meme in
MemeView(memes: self.$memes, memeid: meme.memeid)
}
}
}
.onAppear{
memes.append(MemeModel(memeid: 1, title: "meme1", pic: "bla.jpg"))
memes.append(MemeModel(memeid: 2, title: "meme2", pic: "joo.jpg"))
memes.append(MemeModel(memeid: 3, title: "meme3", pic: "das.jpg"))
memes.append(MemeModel(memeid: 4, title: "meme4", pic: "fsf.jpg"))
memes.append(MemeModel(memeid: 5, title: "meme5", pic: "asd.jpg"))
memes.append(MemeModel(memeid: 6, title: "meme6", pic: "dfvr.jpg"))
memes.append(MemeModel(memeid: 7, title: "meme7", pic: "fsfdf.jpg"))
memes.append(MemeModel(memeid: 8, title: "meme8", pic: "axaxe.jpg"))
}
}
}
}
struct MemeView: View {
@Environment(\.dismiss) var dismiss
func closeThisView(){
DispatchQueue.main.async {
self.dismiss()
}
}
@AppStorage("userid") var userid: Int = 0
@Binding var memes: [MemeModel]
@Binding var memeid: Int
var body: some View {
VStack(spacing: 20){
Text(String(memeid))
NavigationLink{
Comments()
} label: {
Text("comments")
}
}
}
}
struct Comments: View {
@AppStorage("userid") var userid: Int = 0
var body: some View {
VStack{
Text("comments view")
}
}
}
struct MemeModel: Codable {
var memeid: Int
var title: String
var pic: String
}
Код: Выделить всё
commentsКак это исправить ? Какой -нибудь обходной путь?>
Подробнее здесь: https://stackoverflow.com/questions/785 ... e-when-des