2017-10-02 3 views
0

누군가가 이것이 작동하지 않는 이유를 알고 있습니까? tableView는 비어 있으며 데이터베이스와 저장소에 항목이 있어도 아무 것도 표시하지 않습니다. 내가 붙여 넣은이 코드의 맨 아래에 볼 수있는 저장소에서 이미지로드를 구현하기 전에이 문제가 없었습니다. food.append() 문이 storageRef.getData() 클로저 (이전에는 존재하지 않았으므로) 외부에서 사용되었지만, 그것을 닫으면 이제 recipeImage에 액세스 할 수 없으므로 꺼내십시오. 그것이 폐쇄 상태에 있기 때문에 작동하지 않습니까? 그렇다면 어떻게 수정해야합니까? recipeName! 설명 :firebase에서 이미지를 신속하게로드

let parentRef = Database.database().reference().child("Recipes") 
    let storage = Storage.storage() 

    parentRef.observe(.value, with: { snapshot in 

     //Processes values received from server 
     if (snapshot.value is NSNull) { 

      // DATA WAS NOT FOUND 
      print("– – – Data was not found – – –") 

     } else { 

      //Clears array so that it does not load duplicates 
      food = [] 

      // DATA WAS FOUND 
      for user_child in (snapshot.children) { 

       let user_snap = user_child as! DataSnapshot 
       let dict = user_snap.value as! [String: String?] 

       //Defines variables for labels 
       let recipeName = dict["Name"] as? String 
       let recipeDescription = dict["Description"] as? String 
       let downloadURL = dict["Image"] as? String 

       let storageRef = storage.reference(forURL: downloadURL!) 

       storageRef.getData(maxSize: 1 * 1024 * 1024) { (data, error) -> Void in 

        let recipeImage = UIImage(data: data!) 

        food.append(Element(name: recipeName!, description: recipeDescription!, image: recipeImage!)) 
       } 
      } 
      self.tableView.reloadData() 
     } 
    }) 
+1

후 recipeDescription !, image : recipeImage!))', 어떤 행동을 참조하십시오? – 3stud1ant3

+0

IT 작업! 고맙습니다. – random1234

+0

위대한, 대답으로 추가했습니다 – 3stud1ant3

답변

1

이동

self.tableView.reloadData() 

당신이`food.append (요소 (이름 뒤에``self.tableView.reloadData()를 이동하는 경우

food.append(Element(name: recipeName!, description: recipeDescription!, image: recipeImage!))