小编Rin*_*yçi的帖子

使用Alamofire(Swift 2)从JSON填充tableview单元格

我有以下代码.

import UIKit
import Alamofire

class CheHappyTableViewController: UITableViewController, NSURLConnectionDelegate {

    var happyHours = [HappyHour]()

    override func viewDidLoad() {
        super.viewDidLoad()

        //Load the cell elements
        loadHappyHourElements()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    func loadHappyHourElements(){

        let testhappyhour:HappyHour = HappyHour(title: "TEST", image: "TESST", description: "TEST", postedDate: "TEST")
        self.happyHours.append(testhappyhour)

        let url:String = "https://gist.githubusercontent.com/arianitp/036133ebb5af317a595c/raw/f134ec241ec3126bedd6debe5de371e3e01d225b/happyhours.json"
        Alamofire.request(.GET, url, encoding:.JSON).responseJSON
            { response in switch response.result {
            case .Success(let JSON):
                let response = JSON as! NSArray
                for item in response …
Run Code Online (Sandbox Code Playgroud)

json uitableview ios swift alamofire

9
推荐指数
1
解决办法
6382
查看次数

标签 统计

alamofire ×1

ios ×1

json ×1

swift ×1

uitableview ×1