Swift Alamofire发出多个请求,然后重新加载表

时间:2015-01-05 19:30:02

标签: swift alamofire

我使用这段代码,但重载表似乎总是在alamofire请求之后直接加载,而不是先填充数据。大括号以正确的方式放置,但它仍然在步骤2之前加载步骤3。

输出:   - 根据过滤器,过滤器列表不是空的填充数据。  - 步骤1   - 第3步   - 第2步:为哈勒姆找到35栋房屋   - 第2步:为阿姆斯特丹找到100所房子

println("The filter list is not empty filling data according to filters.")
        if let castedFilters = filters as? [Filter] {
            println("step 1")
            for filter in castedFilters{
                var parameters : [String : NSObject] = ["apisleutel": "#########", "module": "Objecten", "get": "Huur", "plaats": filter.plaats, "pt": filter.maximumprijs, "pv": filter.minimumprijs, "wov": filter.oppervlakte, "ka": filter.kamers, "output": "json"]

                self.makeCall(parameters) { responseObject, error in
                    let json = JSON(responseObject!)
                    /**/
                    let count: Int? = json["Response"]["objecten"]["object"].array?.count
                    if((count) != nil)
                    {
                        println("step 2: found \(count!) houses for "+filter.plaats)

                        if let ct = count {
                            for index in 0...ct-1 {
                                //Adding house to houses array
                                var adres = json["Response"]["objecten"]["object"][index]["adres"].string
                                let newHouse = House(straat: adres!)
                                self.houses.append(newHouses)
                            }
                        }
                    }
                    else
                    {
                        let alert = UIAlertView()
                        alert.title = "Fout"
                        alert.message = "No houses found, consider changing the filters."
                        alert.addButtonWithTitle("Ok")
                        alert.show()
                    }
                    return
                }

            }
            println("step 3")
            tableView.reloadData()
        }

通话功能

func makeCall(parameters: [String : NSObject], completionHandler: (responseObject: NSDictionary?, error: NSError?) -> ()) {
    var heap: NSDictionary
    Alamofire.request(.GET, "http://www.huizenzoeker.nl/api/v2/", parameters: parameters)
        .responseJSON { request, response, responseObject, error in
            completionHandler(responseObject: responseObject as? NSDictionary, error: error)
    }
}

0 个答案:

没有答案