Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.73 KB | None | 0 0
  1. override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  2.  
  3. // You already have a custom cell defined - RequestsCell - but you're not using it
  4. // by creating cell as the specific type, you already have outlets for the labels you're populating
  5.  
  6. let cell = tableView.dequeueReusableCell(withIdentifier: "RequestsCell", for: indexPath) as! RequestsCell
  7.  
  8. if rideRequests.count == 0 {
  9. cell.lblUsername.text = "No requests available"
  10. cell.lblLocation.text = "None"
  11. cell.lblDestination.text = "None"
  12.  
  13. cell.lblBidCount.text = ""
  14. cell.lblDistance.text = ""
  15. cell.lblFarePrice.text = ""
  16. cell.imageViewRider.image = UIImage(named: "user-placeholder.jpg")
  17. // always replace with placeholder, as the cells are re-used
  18.  
  19.  
  20. } else {
  21. // changed all of this to use the constructor for RideRequest
  22. let request = RideRequest(snapshot: self.rideRequests[indexPath.row])
  23.  
  24. if request.bids.count == 1 {
  25. cell.lblBidCount.text = "1 bid"
  26. } else {
  27. cell.lblBidCount.text = String("(request.bids.count) bids")
  28. }
  29.  
  30. cell.lblUsername.text = request.username
  31.  
  32. cell.lblLocation.text = request.currentAddress
  33. cell.lblDestination.text = request.destAddress
  34.  
  35. if request.farePrice == 0 {
  36. cell.lblFarePrice.text = "Unknown"
  37. } else {
  38. cell.lblFarePrice.text = String(format: "%0.2f", request.farePrice)
  39. }
  40.  
  41.  
  42. // if we have a profile pic defined, then use it
  43. let indexDetails = getIndexAdditionalDetails(riderID: request.userId)
  44. if indexDetails != nil {
  45. if requestAdditionalDetails[indexDetails!].profilePic != nil {
  46. cell.imageViewRider.image = requestAdditionalDetails[indexDetails!].profilePic
  47.  
  48. } else {
  49. cell.imageViewRider.image = UIImage(named: "user-placeholder.jpg")
  50. // we can get an index before the image is ready, so use default until complete
  51. }
  52.  
  53. var estimateText = "Distance ..."
  54. if requestAdditionalDetails[indexDetails!].estimatedDistance != nil {
  55. estimateText = displayDistance(distance: requestAdditionalDetails[indexDetails!].estimatedDistance!)
  56.  
  57. if requestAdditionalDetails[indexDetails!].estimatedTime != nil {
  58. estimateText = estimateText.appending(", ").appending(displayTime(timeInSeconds: requestAdditionalDetails[indexDetails!].estimatedTime!))
  59. }
  60. }
  61.  
  62. cell.lblDistance.text = estimateText
  63. }
  64. }
  65.  
  66. return cell
  67.  
  68. }
  69.  
  70. destination?.destLat = (destLat.value as? Double)!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement