Hello, please tell me when parsing with TableViewCell? The data in the ViewController is not loaded correctly. What else do I need to add? Here is my code.

import UIKit import Parse class DetailSportViewController: UIViewController { @IBOutlet weak var imageDetail: UIImageView! @IBOutlet weak var textView: UITextView! @IBOutlet weak var titleDetail: UILabel! @IBOutlet weak var prognozDetail: UILabel! var soccers : Soccer? override func viewDidLoad() { super.viewDidLoad() textView.font = textView.font?.withSize(10) detailObject() } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) } @IBOutlet weak var outClose: UIButton! { didSet { outClose.layer.cornerRadius = 20 outClose.layer.masksToBounds = true } } @IBAction func actionClose(_ sender: Any) { dismiss(animated: false, completion: nil) } func detailObject() { let query = PFQuery(className: "soccer") query.findObjectsInBackground { (objects: [PFObject]?, error) -> Void in if error == nil { for object in objects! { let imageDetail = object["detailImageS"] as? PFFile imageDetail?.getDataInBackground(block: { (data, error) -> Void in if error == nil { if let image = data { self.imageDetail.image = UIImage(data: image) self.prognozDetail.text = object["detailPrognozS"] as? String self.textView.text = object["detailTextS"] as? String self.titleDetail.text = object["detailTitleS"] as? String } } }) } } } } 
  • What is parsing with a TableViewCell? What are you speaking about? PS I advise you to make a detailObject () refactor, otherwise it turns out pyramid of doom. And to read such code is very difficult. - Vitali Eller
  • I read it carefully, your question is not at all clear about what I mean. And what does the mix mean? And how do you transfer data from the cell to the controller? - Vitali Eller
  • So I have a “football” class here. I indicated the name of the match and the date (This is in my tableViewCell) I made him a custom discovery. I have this View Controller and my code has published. .And made 4 matches. So here it all goes to scatter. - Aleksandr Ilin
  • In the table or in the controller? - Vitali Eller
  • Well, show me what's being recorded and what you expect instead. I did not understand the question at all. - kxko

1 answer 1

You need to find the desired object in the array and exit the loop.

 for object in objects { if object.id == objectID { // Тут сетите нужные данные break } } 
  • I think if I have such a reason. Generally remove the cycle. Why is it here. - Aleksandr Ilin
  • Well, it already depends on your decision =) - Vitali Eller
  • Vitaly, tell me how to parse the ViewController correctly without a loop, have I not found any articles? - Aleksandr Ilin
  • In theory, you should transfer the necessary data immediately to the controller. As an option, it may be possible to request not all objects, but only an object with the necessary id, for example, I myself did not work with Parse, I do not know its API. - Vitali Eller