Note that there are some explanatory texts on larger screens.

plurals
  1. POPass CLLocation data to UITableView
    text
    copied!<p>I'm trying to load my UITableView with distance from current location. I'm taking small steps in just trying to get the Latitude to load into the UITableView. My NSLog is reading the correct Lat/Long, but my Table is reading 0.000. At this point I'm not sure if it's my memory management or something else. Please help.</p> <p>My ViewController.h</p> <pre><code>#import &lt;UIKit/UIKit.h&gt; #import "CoreLocation/CoreLocation.h" @interface TulsaMasterViewController : UITableViewController &lt;CLLocationManagerDelegate&gt; { NSArray *_barInfo; CLLocationManager *lm; NSString *currentLat; } @property (nonatomic, strong) NSArray *barInfo; @property (nonatomic, strong) NSString *currentLat; @end </code></pre> <p>My ViewController.m</p> <pre><code>#import "TulsaMasterViewController.h" #import "TulsaDetailViewController.h" #import "Bars.h" #import "BarDatabase.h" @implementation TulsaMasterViewController @synthesize barInfo = _barInfo; @synthesize currentLat = _currentLat; - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { NSLog(@"%f", newLocation.coordinate.latitude); NSLog(@"%f", newLocation.coordinate.longitude); currentLat = [NSString stringWithFormat:@"%f", newLocation.coordinate.latitude]; } - (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error { NSString *msg = [[NSString alloc]initWithString:@"Error obtaining location"]; UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Error" message:msg delegate:nil cancelButtonTitle:@"Done" otherButtonTitles:nil]; [alert show]; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [self.barInfo count]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; } //Get the object from the array. Bars *barObj = [self.barInfo objectAtIndex:indexPath.row]; //Set the coffename. cell.textLabel.text = barObj.barName; cell.detailTextLabel.text = [NSString stringWithFormat:@"%f", currentLat]; // Set up the cell return cell; } - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if ([[segue identifier] isEqualToString:@"ShowDetails"]) { TulsaDetailViewController *detailViewController = [segue destinationViewController]; detailViewController.detailItem = [self.barInfo objectAtIndex:[self.tableView indexPathForSelectedRow].row]; } } - (void)awakeFromNib { [super awakeFromNib]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Release any cached data, images, etc that aren't in use. } #pragma mark - View lifecycle - (void)viewDidLoad { [super viewDidLoad]; self.barInfo = [BarDatabase database].barInfo; lm = [[CLLocationManager alloc] init]; lm.delegate = self; [lm startUpdatingLocation]; } @end </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload