0

現在の場所からの距離でUITableViewを読み込もうとしています。LatitudeをUITableViewにロードするために、小さな手順を実行しています。NSLogは正しい緯度/経度を読み取っていますが、テーブルは0.000を読み取っています。この時点では、それが私のメモリ管理なのか他の何かなのかわかりません。助けてください。

私のViewController.h

#import <UIKit/UIKit.h>  
#import "CoreLocation/CoreLocation.h"

@interface TulsaMasterViewController : UITableViewController <CLLocationManagerDelegate>
{   
    NSArray *_barInfo;
    CLLocationManager *lm; 
    NSString *currentLat; 
}

@property (nonatomic, strong) NSArray *barInfo;
@property (nonatomic, strong) NSString *currentLat;

@end

私のViewController.m

#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
4

1 に答える 1

0

didUpdateToLocationメソッドが呼び出されたら、テーブルビューを更新する必要があります

于 2012-06-13T18:17:09.263 に答える