我有一个必须在Json完全放入Joblist数组后创建/刷新的tableview。然后tableview可以正确显示Joblist数组。 但是如果我在for循环后刷新tablebiew,它会显示0记录。我必须刷新for循环中的tableview。它工作正常,但如果joblist数组有大量记录,那么这样做并不是一个好主意。 请帮助解决这个问题。
func parseJSON(json:Any){
locationManager = CLLocationManager()
if let okJSON = json as? [Any]{
for item in okJSON {
let infoDictionary = item as! [String:String]
if let address = infoDictionary["City"] {
let geoCoder = CLGeocoder()
geoCoder.geocodeAddressString(address) { (placemarks, error) in
if error == nil && (placemarks?.count)! > 0 {
let location2 = placemarks?[0].location
if let location1 = self.locationManager?.location {
let distanceInMeters = location1.distance(from: location2!)
let IntDis = Int(distanceInMeters)
//print(IntDis)
if IntDis < 40000 {
print(address)
if let activityid = infoDictionary["ActivityID"] {self.newJob.ActivityID=activityid}
if let companyname = infoDictionary["CompanyName"] {self.newJob.CompanyName=companyname}
if let quantity = infoDictionary["Quantity"] {self.newJob.Quantity=quantity}
if let coupontitle = infoDictionary["Title"] {self.newJob.CouponTitle=coupontitle}
if let couponterms = infoDictionary["Terms"] {self.newJob.CouponTerms=couponterms}
if let expirdate = infoDictionary["ExpirDate"] {self.newJob.ExpirDate=expirdate}
if let contactperson = infoDictionary["ContactPerson"] {self.newJob.ContactPerson=contactperson}
if let tel = infoDictionary["TEL"] {self.newJob.TEL=tel}
self.joblist.append(self.newJob)
print(self.joblist)
//self.tableView.reloadData()
}
}
}
}
}
}
}
}