Loading view trying to remove previous view from stack
Scratching my head on this:
I have a viewController with a "loading..." view that is called when I load another viewController with a MapKit view which searches for a location.
On this "Loading..." view there is a cancel button which when clicked switches the view to the starting viewController. What is happening is when I switch to the starting view, the Map View still in the stack and updating the location in the background. I tried [locationmanager stopupdatinglocation] and I cannot get it to stop updating. All I need is to remove the map view from the stack alltogether,
Can anyone help ?
Thanks
This is the back button code from the loading... view:
-(void)back{
[UIApplication sharedApplication].networkActivityIndicatorVisible=NO;
Car_Park_AppViewController *appView = [[Car_Park_AppViewController a开发者_JS百科lloc]initWithNibName:@"Car_Park_AppViewController" bundle:nil];
appView.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:appView animated:YES];
[appView release];
}
map view code
- (void)viewDidLoad
{
[super viewDidLoad];
mapView.mapType = MKMapTypeSatellite;
mapView.showsUserLocation=TRUE;
loading *loadingView = [[loading alloc] init];
[super.view addSubview:loadingView.view];
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate=self;
locationManager.distanceFilter = kCLDistanceFilterNone; locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
CLLocationCoordinate2D location;
location.latitude = mapView.userLocation.location.coordinate.latitude;
location.longitude = mapView.userLocation.location.coordinate.longitude;
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
MyManager *mng = [MyManager sharedManager];
mng.startLocation = newLocation;
MKCoordinateSpan span;
span.latitudeDelta=.00001;
span.longitudeDelta=.00001;
MKCoordinateRegion region;
region.center = newLocation.coordinate;
region.span=span;
[mapView setRegion:region animated:TRUE];
i++;
NSTimeInterval locationAge = -[mng.endLocation.timestamp timeIntervalSinceNow];
NSLog(@"Accuracy %f",newLocation.horizontalAccuracy);
if ((locationAge < 5.0) && (newLocation.horizontalAccuracy < 30.1)){
[self recLocation];
i=0;
}
haveAlreadyReceivedCoordinates = YES;
}
Try using UINavigationController: http://developer.apple.com/library/ios/#documentation/uikit/reference/UINavigationController_Class/Reference/Reference.html
http://www.iosdevnotes.com/2011/03/uinavigationcontroller-tutorial/
Then you will have a stack of views where you can push and pop views, just like you wanted.
Have some flag for that. Once the cancel is pressed, set that flag to NO. And sont reload the view if the flag is NO.
精彩评论