iOS UITableView没有响应Swift中的reloadData()请求

时间:2016-01-01 05:48:56

标签: ios swift uitableview alamofire reloaddata

我正在使用SwiftyJSON解析数据。数据是通过Alamofire提出的API请求收到的。出于某种原因,当我使用reloadData() UITableView方法时,UITableView没有任何反应。我正在使用UITableViewViewController Swift类,因此无需为IBOutlet创建UITableView ......是否真的如此?我还确保我也正在获取数据并正确解析它。以下是我的代码,任何人都可以找出问题所在吗?

    func search(searchTerm: String) {

    var finalSearchQuery: String = String()

    for objects in searchTerm.characters {

        if objects == " " {

            finalSearchQuery = finalSearchQuery + "+"

        } else {

            finalSearchQuery = finalSearchQuery + "\(objects)"

        }

    }

    print(finalSearchQuery)

    Alamofire.request(.GET, "https://cranbrook.myschoolapp.com/api/directory/directoryresultsget?directoryId=449&searchVal=\(finalSearchQuery)&facets=&searchAll=false").responseJSON { response in

        var instanceSearchResult: SearchResult!

        for object in JSON(response.result.value!) {

            let firstName: String = object.1["FirstName"].stringValue
            let lastName: String = object.1["LastName"].stringValue
            let email: String = object.1["Email"].stringValue
            let largeFilename: String = object.1["LargeFileName"].stringValue
            let addressLine1: String = object.1["AddressLine1"].stringValue
            let city: String = object.1["City"].stringValue
            let state: String = object.1["State"].stringValue
            let zip: String = object.1["Zip"].stringValue
            let homePhone: String = object.1["HomePhone"].stringValue
            let gradYear: String = object.1["GradYear"].stringValue
            let gradeDisplay: String = object.1["GradeDisplay"].stringValue
            let gradeNumericDisplay: String = object.1["GradeNumericDisplay"].stringValue

            instanceSearchResult = SearchResult(firstName: firstName, lastName: lastName, email: email, largeFilename: largeFilename, addressLine1: addressLine1, city: city, state: state, zip: zip, homePhone: homePhone, gradYear: gradYear, gradeDisplay: gradeDisplay, gradeNumericDisplay: gradeNumericDisplay)

            self.tableView.reloadData()

            print(instanceSearchResult)

        }

        self.searchResult?.append(instanceSearchResult)

    }

    ProgressHUD.showSuccess("Done")
    print("search conplete")

}

1 个答案:

答案 0 :(得分:2)

尝试将SearchResult追加到searchResult数组后重新加载表。

我认为这对你有用。

{{1}}