2017-10-02 1 views
-1

이 코드는 콘솔과 데이터에서 잘 작동합니다. 그러나 .................. .................................................. ..... 테이블 뷰 셀에서 비어있는 ................ 데이터를 눌러야합니까? 데이터가 콘솔에로드되었지만 테이블 뷰 셀에로드되지 않습니다.

@IBOutlet weak var tMenPro: UITableView! 
    var nameArray = [String]() 
    var imgURLArray = [String]() 
override func viewDidLoad() { 
     super.viewDidLoad() 
     self.downloadJsonWithURL() 
     //self.nameArray.removeAll() 
     self.tMenPro.reloadData() 
     tMenPro.delegate = self 
     tMenPro.dataSource = self 
     self.slider() 
     // Do any additional setup after loading the view . 

      } 

func downloadJsonWithURL() { 
     Alamofire.request("http://...../api/products", method: .post, parameters: ["gender":"Men"], encoding: JSONEncoding.default) 
      .responseJSON { (DataResponse) in 
       print(DataResponse) 
     } 
     OperationQueue.main.addOperation({ 
      self.tMenPro.reloadData() 
     }) 
    } 


    func numberOfSections(in tableView: UITableView) -> Int { 
     return 1 
    } 
     func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
     return nameArray.count 
    } 
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
     let cell = tableView.dequeueReusableCell(withIdentifier: "himCell", for: indexPath) as! HimProud 
     cell.himLbl.text = nameArray[indexPath.row] 
     //cell.dobLabel.text = adobArray[indexPath.row] 

     let imgURL = NSURL(string: imgURLArray[indexPath.row]) 
     cell.himImg.image = UIImage() 
     if imgURL != nil { 
      Alamofire.request("http://luxgems.co.uk/api/products", method: .post, parameters: ["main_image":""]).responseData { response in 
       debugPrint(response) 

       // print(response.request!) 
       // print(response.response!) 
       debugPrint(response.result) 

       if let imageData = response.result.value{ 
        cell.himImg.image = UIImage.init(data: imageData) 
       } 
      } 
      let data = NSData(contentsOf: (imgURL as URL?)!) 
      cell.himImg.image = UIImage(data: data! as Data) 
     } 
     return cell 

    } 
+0

... MVCE ............................... – the4kman

+0

을 제공해주세요. 다음번에는 너무 많은 코드와 충분한 텍스트가 없다는 것을 알게되면 내 문제 – ateek

답변

0

있는 tableView 다시로드는 완성의 일부가 될 필요가 ............................ 함께 도와주세요 요청 처리기.

func downloadJsonWithURL() { 
    Alamofire.request("http://luxgems.co.uk/api/products", method: .post, parameters: ["gender":"Men"], encoding: JSONEncoding.default) 
     .responseJSON { (DataResponse) in 
      print(DataResponse) 
      OperationQueue.main.addOperation({ 
       self.tMenPro.reloadData() 
      }) 
    } 
} 

그리고 물론 nameArray을 입력해야합니다.

+0

을 설명하기 위해 항상 걸릴 것입니다. 어떻게 할 수 있습니까? – ateek

+0

글쎄, 그건 달라. Google에서 'json to array swift'를 선택하면 많은 아이디어를 찾을 수 있습니다. –

+0

괜찮습니다. 정말 고마워요. – ateek

관련 문제