ios - Data passing from model not showing in UI after using Alamofire -


so have created model download data (images, title, desc) using alamofire. having problem pass data , update in viewcontroller. if put functions in viewcontroller's viewdidload working fine. want use mvc model. here code model:

class pagecontrollerview {     var _titlename : string!     var _titledesc : string!     var _image : uiimage!      var titlename : string {         if _titlename == nil {             _titlename = ""             print("titlename nil")         }         return _titlename     }      var titledesc : string {         if _titledesc == nil {             print("tittledesc nile")             _titledesc = ""         }         return _titledesc     }      var image : uiimage {         if _image == nil {             print("image view nill")             _image = uiimage(named: "q")         }         return _image     }      func getpagecontrollerdata(_ page : int) {         alamofire.request("\(base_url)movie/now_playing?api_key=\(api_key)&language=en-us&page=1").responsejson { (response) in              if let json = response.result.value {                  if let json = json as? dictionary<string, any> {                     if let results = json["results"] as? [dictionary<string, any>] {                         if let overview = results[page]["overview"] as? string {                             self._titledesc = overview                         }                         if let releasedate = results[page]["release_date"] as? string {                             if let title = results[page]["title"] as? string {                                 let index = releasedate.index(releasedate.startindex, offsetby: 4)                                 self._titlename = "\(title) (\(releasedate.substring(to: index)))"                             }                         }                         if let image_url = results[page]["poster_path"] as? string{                              alamofire.request("\(base_url_image)\(image_size)\(image_url)").downloadprogress(closure: { (progress) in                                 print(progress.fractioncompleted)                              }).responsedata(completionhandler: { (response) in                                 print("completed downloading")                                 if let imagedata = response.result.value {                                     self._image = uiimage(data: imagedata)                                 }                             })                          }                     }                 }             }         }       }   } 

and viewcontrollers code (it working fine want pass model. alamofirefuntion present in viewcontroller):

override func viewdidload() {             super.viewdidload()             print("viewdidload")             getpagecontrollerdata(13)             self.updatepagecontrollerui()         }      func updatepagecontrollerui() {             pagecontrollermovielabel.text = pagecontrollerview.titlename             pagecontrollersublabel.text = pagecontrollerview.titledesc             pagecontrolimageview.image = pagecontrollerview.image          }  func getpagecontrollerdata(_ page : int) {         alamofire.request("\(base_url)movie/now_playing?api_key=\(api_key)&language=en-us&page=1").responsejson { (response) in              if let json = response.result.value {                  if let json = json as? dictionary<string, any> {                     if let results = json["results"] as? [dictionary<string, any>] {                         if let overview = results[page]["overview"] as? string {                             self.pagecontrollersublabel.text = overview                         }                         if let releasedate = results[page]["release_date"] as? string {                             if let title = results[page]["title"] as? string {                                 let index = releasedate.index(releasedate.startindex, offsetby: 4)                                 self.pagecontrollermovielabel.text = "\(title) (\(releasedate.substring(to: index)))"                             }                         }                         if let image_url = results[page]["poster_path"] as? string{                              alamofire.request("\(base_url_image)\(image_size)\(image_url)").downloadprogress(closure: { (progress) in                                 print(progress.fractioncompleted)                             }).responsedata(completionhandler: { (response) in                                  if let imagedata = response.result.value {                                      self.pagecontrolimageview.image = uiimage(data: imagedata)                                 }                             })                          }                     }                 }             }         }      }  

my question how pass model can use this, using pagecontrollerview object.

override func viewdidload() {         super.viewdidload()         print("viewdidload")         pagecontrollerview.getpagecontrollerdata(13)         self.updatepagecontrollerui()     } 

now have checked code works image still not shown @ firstgo since has not been downloaded title , description showing.

override func viewdidload() {         super.viewdidload()         print("viewdidload")         pagecontrollerview.getpagecontrollerdata(4)       }      override func viewdidappear(_ animated: bool) {         super.viewdidappear(animated)         self.updatepagecontrollerui()     } 


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -