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 
<UITableViewDelegate, UITableViewDataSource, CLLocationManagerDelegate> {

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.

Artjom B.
  • 61,146
  • 24
  • 125
  • 222
Atma
  • 29,141
  • 56
  • 198
  • 299

1 Answers1

2

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
  • 12,139
  • 3
  • 29
  • 30
  • if my implementation class is the tableview and not my nib file how do it reload the tableview? – Atma Apr 02 '09 at 02:17
  • You have to set a reference to it, either an ivar or an outlet. – August Apr 02 '09 at 12:13
  • how would i set an outlet if this is what my interface looks like: @interface RootViewController : UITableViewController { – Atma Apr 02 '09 at 16:17
  • also uitableview doesn't have a reloaddata method. Am i doing something wrong? – Atma Apr 02 '09 at 16:32
  • I'd take a closer look at the documentation. UITableView most definitely has a reloadData method. – August Apr 02 '09 at 21:34