distanceInMeters Problems with arrays and sort

后端 未结 3 1834
野性不改
野性不改 2020-12-04 03:54

I want to sort my TableView by distance, but I have mixed up:( Please help me if You can, I would appreciate it, really :(

I have an array with 100 objects.

3条回答
  •  [愿得一人]
    2020-12-04 04:52

    Use of unresolved identifier 'mall'

    => There is nothing named "mall" in the scope of the function locationManager didUpdateLocations. Meaning: locationManager didUpdateLocations has no clue what happens inside of tableView cellForRowAt indexPath and vice versa.


    You could solve this problem by applying following steps to your code:

    1. Move the distance calculation from
      locationManager didUpdateLocations
      to
      tableView cellForRowAt indexPath
    2. add a property to your class that stores the current position:
      var currentPosition: CLLocation? = nil

    3. Store the position you receive in locationManager didUpdateLocations to the currentPosition property

    4. Add self.tableView.reloadData() after you received and assigned the position
    5. Use the mall and the currentPosition in cellForRowAt to calculate the distance and update the distanceLabel
    6. Keep in mind that currentPosition can be nil and the distance can not be calculated => make label empty or add something like "unknown distance" to it

提交回复
热议问题