Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- // You already have a custom cell defined - RequestsCell - but you're not using it
- // by creating cell as the specific type, you already have outlets for the labels you're populating
- let cell = tableView.dequeueReusableCell(withIdentifier: "RequestsCell", for: indexPath) as! RequestsCell
- if rideRequests.count == 0 {
- cell.lblUsername.text = "No requests available"
- cell.lblLocation.text = "None"
- cell.lblDestination.text = "None"
- cell.lblBidCount.text = ""
- cell.lblDistance.text = ""
- cell.lblFarePrice.text = ""
- cell.imageViewRider.image = UIImage(named: "user-placeholder.jpg")
- // always replace with placeholder, as the cells are re-used
- } else {
- // changed all of this to use the constructor for RideRequest
- let request = RideRequest(snapshot: self.rideRequests[indexPath.row])
- if request.bids.count == 1 {
- cell.lblBidCount.text = "1 bid"
- } else {
- cell.lblBidCount.text = String("(request.bids.count) bids")
- }
- cell.lblUsername.text = request.username
- cell.lblLocation.text = request.currentAddress
- cell.lblDestination.text = request.destAddress
- if request.farePrice == 0 {
- cell.lblFarePrice.text = "Unknown"
- } else {
- cell.lblFarePrice.text = String(format: "%0.2f", request.farePrice)
- }
- // if we have a profile pic defined, then use it
- let indexDetails = getIndexAdditionalDetails(riderID: request.userId)
- if indexDetails != nil {
- if requestAdditionalDetails[indexDetails!].profilePic != nil {
- cell.imageViewRider.image = requestAdditionalDetails[indexDetails!].profilePic
- } else {
- cell.imageViewRider.image = UIImage(named: "user-placeholder.jpg")
- // we can get an index before the image is ready, so use default until complete
- }
- var estimateText = "Distance ..."
- if requestAdditionalDetails[indexDetails!].estimatedDistance != nil {
- estimateText = displayDistance(distance: requestAdditionalDetails[indexDetails!].estimatedDistance!)
- if requestAdditionalDetails[indexDetails!].estimatedTime != nil {
- estimateText = estimateText.appending(", ").appending(displayTime(timeInSeconds: requestAdditionalDetails[indexDetails!].estimatedTime!))
- }
- }
- cell.lblDistance.text = estimateText
- }
- }
- return cell
- }
- destination?.destLat = (destLat.value as? Double)!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement