gpt4 book ai didi

ios - 我的程序没有错误,但没有显示所需的用户名和与司机的距离,因为它应该

转载 作者:行者123 更新时间:2023-11-30 13:06:29 25 4
gpt4 key购买 nike

这是要调用的类:

import Foundation
import MapKit

class Requests {
private var _username:String!
private var _key:String!
var distanceFromDriver:Double! = 0.0
private var _latitude:CLLocationDegrees!
private var _longitude:CLLocationDegrees!
private var _location:CLLocation!
private var _driverLocation:CLLocation!

var username:String {
return _username
}

var key:String {
return _key
}

var latitude:CLLocationDegrees {
return _latitude
}

var longitude:CLLocationDegrees {
return _longitude
}

var location: CLLocation {
return self._location
}

init(uid:String, dictionary: Dictionary<String, AnyObject>, driverLocation:CLLocation, tView: UITableView) {

self._key = uid
self._driverLocation = driverLocation

if let lat = dictionary["Latitude"] as? Double {

self._latitude = lat

}

if let long = dictionary["Longitude"] as? Double {

self._longitude = long

}

if let email = dictionary["Email"] as? String {

self._username = email

}
let riderLocation = CLLocation(latitude: self._latitude, longitude: self._longitude)
self._location = riderLocation


let distanceInKM = _driverLocation.distanceFromLocation(riderLocation)
let miles = (distanceInKM / 1000) * 0.62137
self.distanceFromDriver = miles
tView.reloadData()
}

}

这是需要检索上面的类:

import UIKit
import Firebase
import MapKit
import CoreLocation
import FirebaseAuth


class DriverVC: UITableViewController, MKMapViewDelegate, CLLocationManagerDelegate {



var requests = [Requests]()
var locationManager:CLLocationManager!

@IBOutlet var tableview: UITableView!

override func viewDidLoad() {
super.viewDidLoad()

locationManager = CLLocationManager()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestAlwaysAuthorization()
locationManager.allowsBackgroundLocationUpdates = true
locationManager.startUpdatingLocation()

self.tableView.registerNib(UINib(nibName: "cell", bundle: nil),
forCellReuseIdentifier: "reuseIdentifier")
}


override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}

override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.requests.count
}

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath)

if self.requests.count >= 1 {
self.requests.sortInPlace({$0.distanceFromDriver < $1.distanceFromDriver})

cell.textLabel!.text = String(format: "%.01f \(self.requests[indexPath.row].username)", self.requests[indexPath.row].distanceFromDriver)

} else {
self.requests = []
self.tableView.reloadData()
}

return cell
}
}

最佳答案

我没有足够的点来评论,购买我的后续是:是否显示任何内容(即用户名/距离不显示,是否显示其他内容?如果插入 print() cellForRowAtIndexPath 中的语句您注意到被调用了吗?

关于ios - 我的程序没有错误,但没有显示所需的用户名和与司机的距离,因为它应该,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39303403/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com