How to chager url and update image in swiftUI #1979
              
                
                  
                  
                    Answered
                  
                  by
                    onevcat
                  
              
          
                  
                    
                      hoangnam714
                    
                  
                
                  asked this question in
                Q&A
              
            -
| I have an image view that needs to change the image when it is changed, I am having trouble reloading the KFImage when loading with new urls, can someone help me | 
Beta Was this translation helpful? Give feedback.
      
      
          Answered by
          
            onevcat
          
      
      
        Aug 18, 2022 
      
    
    Replies: 2 comments
-
| 
         Here is a sample running well when changing the URL (or URL string): struct SingleViewDemo : View {
    @State var string = "kingfisher-1.jpg"
    var body: some View {
        KFImage(
            URL(string: "https://raw.githubusercontent.com/onevcat/Kingfisher-TestImages/master/DemoAppImage/Loading/\(string)")
        )
        Button(action: {
            string = "kingfisher-2.jpg"
        }) { Text("Next Image") }
    }
}Any luck to try this code and see if that works? If so, maybe you are having a wrong   | 
  
Beta Was this translation helpful? Give feedback.
                  
                    0 replies
                  
                
            
      Answer selected by
        hoangnam714
-
| 
         Thank @onevcat, Thanks for your reply, have a nice day.  | 
  
Beta Was this translation helpful? Give feedback.
                  
                    0 replies
                  
                
            
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
        
    
Here is a sample running well when changing the URL (or URL string):
Any luck to try this code and see if that works? If so, maybe you are having a wrong
urlin yourButtonaction?