Programming/Swift

tableView에서 JSon하기

ilovecoffee 2015. 5. 6. 16:05

    var shopList : NSArray!


    override func viewDidLoad() {

        super.viewDidLoad()

     let defaults = NSUserDefaults.standardUserDefaults()

               uid = defaults.objectForKey("uid") as! String

            token = defaults.objectForKey("token") as! String

List()

}


    func List() {

        let process = JSONNetwork()

        var arr = ["manager" : "shop", "method" : "get_shop_all", "uid" : uid, "token": token, "page" : "0", "latitude" : "37.49521", "longitude" :"127.03318833333333"]

        process.delegate = self

        process.jsonProccess(arr, code: NetworkCode().GET_SHOP_ALL)

    }

    

    func returnJSON(data: NSDictionary, code: Int) {

        if NetworkCode().GET_SHOP_ALL==code{

            var returnData2 : NSDictionary = data.valueForKey("data") as! NSDictionary

            println("ttt")

            println(returnData2)

            shopList = returnData2.valueForKey("shop_list") as? NSArray

            NSOperationQueue.mainQueue().addOperationWithBlock {

            self.tableView.reloadData()//테이블뷰 재로딩

            }

        }

    }


func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

        // #warning Incomplete method implementation.

        // Return the number of rows in the section.



        

        if (shopList == nil) {

            return 0

        } else {

            return shopList.count

            

        }

        

        

    }


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


        let cell : MainTableViewCell = tableView.dequeueReusableCellWithIdentifier("MainTableViewCell") as! MainTableViewCell

        println("asfdsaf")

        var cellData : NSDictionary! = shopList[indexPath.row] as! NSDictionary

        

        var mcode = cellData.valueForKey("mcode") as! String

        var mname = cellData.valueForKey("mname") as! String

        var shop_type = cellData.valueForKey("shop_type") as! Int

        var address = cellData.valueForKey("address") as! String

        var option_desc = cellData.valueForKey("option_desc") as! String

        var reservation_count = cellData.valueForKey("reservation_count") as! Int

        var favorities_count = cellData.valueForKey("favorities_count") as! Int

        var main_image = cellData.valueForKey("main_image") as! String

        var distance = cellData.valueForKey("distance") as! Int




//        cell.proImage.image = UIImage(named: )

        cell.adressLabel.text = address

        cell.eventLabel.text = option_desc

        cell.reserLabel.text = String(reservation_count)

        cell.favLabel.text = String(favorities_count)

        cell.testLabel.text = mname

        return cell

    }