2016-09-03 2 views
0

が呼び出されるクラスであるとして、ドライバから必要なユーザ名と距離を表示しません:私のプログラムにエラーがないが、それここにする必要があり

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() 
    } 

} 

ここでは、1つを取得する必要があるクラスです上:

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 
    } 
} 
+0

どの言語からそのコードをコピーしましたか?プライベートバッキング変数を持つプロパティだけを定数として読み込むことは、Swiftではばかげている。 'let'を使ってください! – vadian

答えて

0

私は、コメントである私のフォローアップを購入するのに十分なポイントを持っていない。つまり、ユーザ名/距離が表示されない(表示するものがあり、何か表示されますが、挿入した場合は? print()の文はcellForRowAtIndexPathになっています。

+0

numberOfSectionsInTableView プリント( "私のためにライス") リターン1} numberOfRowsInSectionプリント( "私のために豆") 戻りself.requests.count } cellForRowAtIndexPathプリント( "私のために肉" )私はして のために私 ライスため******** ライスを印刷アクションの上 ***** ANS(「私のためにライス」)私 – Matt

+0

numberOfSectionsInTableView プリント私 豆私は ライス私私 ライス ビーンズ リターン1 } numberOfRowsInSection プリント(「私のために豆」) 戻りmyarrayのため.count } cellForRowAtIndexPathプリント( "私のために肉") cell.textLabel?の.text = myarrayの[indexPath.item] 私のために戻りセル} は[ "ITEM1" "ITEM2"、 "ITEM3"] = myarrayのせ super.viewDidLoad() ライス私にとって ライス私にとって 豆私にとって ライス私にとって 豆 私のために私のために私のためにライス私にとって 豆 肉の私のために 肉 肉 – Matt

+0

私は同じのtableViewコントローラ上のviewDidLoadの上方に配置された私の配列値を呼び出すのであれば、それはcellForRowAtIndexPathのものも含め、すべてを印刷し、また、値を表示します私が望むようにSegue View Controller上で。しかし、別のクラスから呼び出すと、cellForRowAtIndexPathの下に何も印刷されず、Segue Viewコントローラに何も表示されません。 – Matt

関連する問題