Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
508 views
in Technique[技术] by (71.8m points)

swift - Text overlaps on If conditional in ForEach statement SwiftUI

I'm trying to show Texts from a ForEach loop after doing an if check. Even though I have VStack inside and outside the ForEach, the text objects appear to overlap. I'm exploring other options as filtering the array but don't understand how to apply that to my conditional. Please let me know if there's an easy way to either have the results inside a VStack or filter the data.

struct LikedView: View {
    @ObservedObject var users = getUserData()
    @ObservedObject var globalCount = GlobalCount()
    @ObservedObject var movies = getMoviesData()
    @State var likedArray = []
    @State var count = 0
    
    var body: some View {
        //Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
        ZStack{
            ForEach(self.users.datas) { alpha in
                ForEach(self.movies.datas) { movies in
                    VStack{
                        ForEach(alpha.loved, id: .self) { item in
                            VStack{
                                if(movies.id == item){
                                    Text(item)
                                }
                            }
                        }
                    }
                }
            }
        }
        .onAppear{
            self.users.fetchData()
            self.movies.fetchData()
        }
        
    }
}

enter image description here

question from:https://stackoverflow.com/questions/65557573/text-overlaps-on-if-conditional-in-foreach-statement-swiftui

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...