views:

509

answers:

1

I'm trying to populate a UITableview with an array of cells. I usually do this from the viewDidLoad method but this time I want to populate the array based on location. Below is the first line of my interface:

@interface RootViewController : UITableViewController {

In the implementation file the viewDidLoad method looks like this:

   - (void)viewDidLoad {

    // for location
    self.locationManager = [[CLLocationManager alloc] init];
    [locationManager startUpdatingLocation];
    locationManager.delegate = self;
    locationManager.distanceFilter = kCLDistanceFilterNone; 
    locationManager.desiredAccuracy = kCLLocationAccuracyBest;


    [super viewDidLoad];
   }

I populate the array of cells in the didUpdateToLocation method:

    self.title = @"Open Buildings";

NSMutableArray *buildingArray = [[NSMutableArray alloc] initWithObjects:building1, 

self.controllers = array;

The title of the view updates when location is found but the array doesn't populate. The array did populate before when I had the above code in the viewdidupdate. I had to move it to the didupdatelocation method because the application won't have the location info when the view loads in the viewDidLoad method.

Please help and thanks!

+1  A: 

Your table view doesn't know you have new data. So, once you have the new data, you need to tell your table view to reload:

[myTableView reloadData];
August
if my implementation class is the tableview and not my nib file how do it reload the tableview?
Buffernet
You have to set a reference to it, either an ivar or an outlet.
August
how would i set an outlet if this is what my interface looks like: @interface RootViewController : UITableViewController <UITableViewDelegate, UITableViewDataSource, CLLocationManagerDelegate> {
Buffernet
also uitableview doesn't have a reloaddata method. Am i doing something wrong?
Buffernet
I'd take a closer look at the documentation. UITableView most definitely has a reloadData method.
August