samedi 25 juin 2016

tableView with prototype cell not reloading data


Hey Guys I'm trying of figure out what i'm doing wrong with no luck

basically I have a webservice that returns some results that I want to put them in table in an iOS app

I am using prototype cell with 3 labels do put the results per line of the table

The problem is that the table is always empty

I checked that no values regarding the web service response are nil

Can anyone Help Me?

import UIKit
import Alamofire
import SwiftyJSON

class DetailsViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {


    @IBOutlet weak var TableDeliveryDetails: UITableView!
    @IBOutlet weak var bostampLabel: UILabel!
    @IBOutlet weak var distribuidorLabel: UILabel!
    @IBOutlet weak var exploracaoLabel: UILabel!
    @IBOutlet weak var dataLabel: UILabel!
    @IBOutlet weak var descargaLabel: UILabel!


    var bostampLabelText=""
    var distribuidorLabelText=""
    var exploracaoLabelText=""
    var dataLabelText=""
    var descargaLabelText=""
    var getsDetailsCollection = [GetDeliveryDetailsClass]()


    override func viewDidLoad() {
        super.viewDidLoad()

        self.TableDeliveryDetails.dataSource=self
        self.TableDeliveryDetails.delegate=self
        self.TableDeliveryDetails.registerClass(TableViewCellDetails.self, forCellReuseIdentifier: "cell")


        //bostampLabel.text=bostampLabelText
        distribuidorLabel.text=distribuidorLabelText
        exploracaoLabel.text=exploracaoLabelText
        dataLabel.text=dataLabelText
        descargaLabel.text=descargaLabelText


        Alamofire.request(.GET, "http://192.168.0.1:1278/api/Delivery/GetDeliveryDetais", parameters: ["stamp": bostampLabelText])
            .responseJSON { response in
                print(response.request)  // original URL request
                print(response.response) // URL response
                print(response.data)     // server data
                print(response.result)   // result of response serialization

                if let JSON = response.result.value {

                    let jsonResults = JSON as! NSArray
                    for var i = 0; i < jsonResults.count; i++ {
                        var produto=jsonResults[i]["Produto"] as! String
                        var qttKg = jsonResults[i]["QuantidadeKG"] as! Double
                        var qttLt = jsonResults[i]["QuantidadeLT"] as! Double
                        var getObj = GetDeliveryDetailsClass(produto:produto,qttKg:qttKg,qttLt:qttLt)

                        self.getsDetailsCollection.append(getObj)
                        // print(add)
                        // TableClienteFinal.append(add)
                    }

                }
                self.reload_table_data()

        }


    }

    func reload_table_data()
    {
        dispatch_async(dispatch_get_main_queue(),{
            self.TableDeliveryDetails.reloadData()
            return
            })
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return self.getsDetailsCollection.count
    }

     func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        return 1
    }


    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {



      //  let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! TableViewCellDetails
        let cell = tableView.dequeueReusableCellWithIdentifier("cell") as! TableViewCellDetails

        let object = self.getsDetailsCollection[indexPath.row]
        cell.columProdutoText=object.produto
        cell.columQttKgText=String(format:"%f", object.qttKg)
        cell.columnQttLtText=String(format:"%f", object.qttLt)
        return cell
    }

Aucun commentaire:

Enregistrer un commentaire