I am intended to do this
I have a tab bar with 5 tab items and the first one is hooked up to TableViewController
I would like the tableview datasource to be determined by the user location like city/state
I have this code in -ViewDidLoad
locationManager = [[CLLocationManager alloc]init];
locationManager.delegate = self;
locationManager.distanceFilter = KCLDistanceFilterNone;
locationManager.desiredAccuracy = LCLLocationAccuracyHunderedMeters;
[locationManager startUpdatingLocation];
and then getting the location in didUpdateToLocation and setting to the userCurrentLocation property.
But I can’t get the userCurrentLocation to determine the datasource for the TableView. Please advise.
Where to set the datasource like the below
if (userLocation == @"Sydney")
{
arrData = [NSMutableArray arrayWithObjects:@"San Francisco",nil];
}
else
{
arrData = [NSMutableArray arrayWithObjects:@"California",nil];
}
Thanks in advance.
You would need to respond to the delegate method
didUpdateToLocations, so I would recommend you to only start loading your tableview after this method is called:That way you will guarantee you got an answer. See the delegate documentation for further information.
Edit:
First you would have to set your class as the a
CLLocationManagerDelegateyou would do that in the header file of your class.Although you would probably have to create your
UITableViewControllerin theviewDidLoadmethod though you would have to add your view controller tho the main view when thedidUpdateToLocationdelegate method is called.If you need something else, let me know.