加载视图试图从堆栈中删除以前的视图

时间:2011-07-19 07:33:32

标签: iphone mapkit

抓住我的头:

我有一个带有“loading ...”视图的viewController,当我使用MapKit视图加载另一个viewController时会调用该视图来搜索位置。

在此“正在加载...”视图中,有一个取消按钮,单击此按钮可将视图切换到起始viewController。发生的事情是当我切换到起始视图时,Map View仍然在堆栈中并在后台更新位置。我试过[locationmanager stopupdatinglocation],我无法让它停止更新。我只需要从堆栈中删除地图视图,

有人可以帮忙吗?

由于

这是加载...视图的后退按钮代码:

-(void)back{
[UIApplication sharedApplication].networkActivityIndicatorVisible=NO;

Car_Park_AppViewController *appView = [[Car_Park_AppViewController alloc]initWithNibName:@"Car_Park_AppViewController" bundle:nil];
appView.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:appView animated:YES];

[appView release];

}

地图视图代码

- (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;
}

2 个答案:

答案 0 :(得分:0)

尝试使用UINavigationController: http://developer.apple.com/library/ios/#documentation/uikit/reference/UINavigationController_Class/Reference/Reference.html

http://www.iosdevnotes.com/2011/03/uinavigationcontroller-tutorial/

然后您将拥有一堆视图,您可以按照自己的意愿推送和弹出视图。

答案 1 :(得分:0)

有一些标志。按下取消后,将该标志设置为NO。如果标志为NO,则重新加载视图。