views:

168

answers:

2

Hi there,

I have a UITableView (on a navigation controller stack) which is showing details for a custom model object. The object has an array property to hold child objects which each have a latitude and longitude property.

As I am 'lazy-loading' everything from a web service API, the array of child objects is not populated until the first time the user taps a cell in the detail view to see the objects on a map. At this point I first create and push an interim 'loading view' which makes the api call, populates the array and then creates and pushes the map view.

The issue is once the map-based view is pushed onto the nav controller it's MKMapView is not showing. The nav bar title and back button change correctly but I can still see the previous loading view between the apps tab bar and nav bar! If the array has been previously populated then I push the map-based view directly after the detail view and it works fine. I am also using this map view controller across my project with no previous problems.

I can't for the life of me get what's going on here. If I change the 'loading' view controller to present the map-view modally then it also works fine. The map view controllers nib was being used by 2 custom controller classes and I intially thought this was the problem - but the files owner in IB is set to the correct controller now.

Here's the code from the loading view which pushes the map view:

ObjectMapViewController *objectMapVC = [[ObjectMapViewController alloc] 
                initWithNibName:@"ObjectLocationView" bundle:nil];

objectMapVC.objectsToMap = self.object.childObjects;

[self.navigationController pushViewController:objectMapVC animated:YES];

[objectMapVC release];

Any help greatly appreciated!

A: 

Fixed this by wrapping the above code in a seperate method and calling using

[self performSelector:@selector(pushMapView) withObject:nil afterDelay:0.3];

once the API call completes.

I'm presuming that the navigation controller didn't have enough time to properly setup its view stack as the API call generally takes under a second to complete so the map view was being pushed almost as soon as the loading view had animated in.

thomh
A: 

The most likely reason for this problem is that you were running your download in a background thread. If in the same thread you show/configure your MapView, that could be an issue. All UI actions must run on main thread. That would explain why the performSelector afteDelay solved the problem.

gonso