Thursday, July 25, 2024
HomeiOS Developmentios - change in viewIndex ought to rerender the view nevertheless it...

ios – change in viewIndex ought to rerender the view nevertheless it doesn’t


what am I lacking? This alteration in viewIndex ought to set off rerender of view nevertheless it doesn’t.
ViewIndex will change the index of consumer to make use of for profileView and it’ll set off rerendering.

import SwiftUI

struct ExploreProfileView: View {
    @State personal var userProfiles: [User]
    @State personal var viewIndex: Int = 0
    
    init(profiles: [User]) {
        self._userProfiles = State(initialValue: profiles)
    }
    
    personal func updateViewIndex() {
        if viewIndex < userProfiles.depend - 1 {
            viewIndex += 1
        } else {
            viewIndex = 0
        }
    }
    
    var physique: some View {
        Group {
            
            if userProfiles.isEmpty {
                
                VStack {
                    Spacer()
                    
                    Textual content("No profile(s) to view")
                    
                    Spacer()
                }
                
            } else {
                
                ZStack {
                    ProfileView(consumer: userProfiles[viewIndex])
                    
                    VStack {
                        Spacer()
                        
                        HStack {
                            Spacer()
                            
                            Textual content("Like")
                                .font(.headline)
                                .onTapGesture {
                                    updateViewIndex()
                                }
                            
                            Spacer()
                            
                            Textual content("Cross")
                                .font(.headline)
                                .onTapGesture {
                                    updateViewIndex()
                                }
                            
                            Spacer()
                        }.padding()
                    }
                }
                
            }
            
        }
        
    }
    
}

I recognized that viewIndex is modified accurately nevertheless it doesn’t set off rerendering of the view.
What’s inflicting this bug?

I attempted to rerender the view after the change in viewIndex and I anticipated the view to vary in each change in viewIndex.



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments