0

ClLocationManagerviewWillAppear. 我是同一个视图控制器,我有一个打开 Web 视图的按钮。当用户点击按钮时,我想立即停止位置管理器。我正在使用[locationManager stopUpdating]locationManager.delegate = nil。从CLLOCATION委托方法我打开MFMailComposer工作表。

问题:即使在单击按钮(打开网页视图)后,我也会MailComposerCode执行。如何阻止它?

-(void)viewWillAppear:(BOOL)animated{

    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:animated];
    [self setUpProgressBar];

    if (webViewButtonClicked == YES)//when user came bck from web view pick up latest coordinates
    {
        webViewButtonClicked = NO;
        [self getLocationCoordinates];
    }
    else//get latest coordinates from CLLocation manger
    {
        if (!locationManager) {
            locationManager = [[CLLocationManager alloc] init];
        }
        if (!self.geocoder) {
            self.geocoder = [[CLGeocoder alloc] init];
        }

        locationManager.delegate = self;
        // This is the most important property to set for the manager. It ultimately determines how the manager will
        // attempt to acquire location and thus, the amount of power that will be consumed.
        locationManager.desiredAccuracy = kCLLocationAccuracyBest;
        // When "tracking" the user, the distance filter can be used to control the frequency with which location measurements
        // are delivered by the manager. If the change in distance is less than the filter, a location will not be delivered.
        locationManager.distanceFilter = kCLLocationAccuracyNearestTenMeters;
        // Once configured, the location manager must be "started".
        [locationManager startUpdatingLocation];
    }
}

- (IBAction)goToWEBVIEW
{
    NSLog(@"setting to YES");

    webViewButtonClicked = YES;
    [locationManager stopUpdatingLocation];
    locationManager.delegate = nil;

    aWebViewController = [[WebViewController alloc] initWithNibName:@"WebViewController" bundle:nil];
    [self.navigationController aWebViewController animated:NO];
}

CLLocationManager委托方法:

-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{
    if (webViewButtonClicked==NO)
    {
        NSLog(@"1234");
        if (!self.sender) {
            [self.gpsActivityindicator stopAnimating];
            [self stopUpdatingLocation:@""];
            self.destinationForProgressView = .25;
            [NSThread detachNewThreadSelector:@selector(startTheBackgroundJob) toTarget:self withObject:nil];
            **[self openMailComposer];**
        }
    }
}

所以你可以在goToWebView方法中看到我有一个标志webViewButtonClicked = YES,但是在用户点击 web 视图按钮之前调用了委托方法。所以条件if (webViewButtonClicked==NO)变成了true?我怎样才能停止这种情况?

谢谢。

4

2 回答 2

0
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{
 [locationManager stopUpdatingLocation];
if (webViewButtonClicked==NO)
{
    NSLog(@"1234");
    if (!self.sender) {
        [self.gpsActivityindicator stopAnimating];
        [self stopUpdatingLocation:@""];
        self.destinationForProgressView = .25;
        [NSThread detachNewThreadSelector:@selector(startTheBackgroundJob) toTarget:self withObject:nil];
        **[self openMailComposer];**
    }
}

}

于 2013-07-01T12:30:23.557 回答
0
- (IBAction)goToWEBVIEW
{
[locationManager stopUpdatingLocation];
 NSLog(@"setting to YES");

webViewButtonClicked = YES;
[locationManager stopUpdatingLocation];
locationManager.delegate = nil;

aWebViewController = [[WebViewController alloc] initWithNibName:@"WebViewController" bundle:nil];
[self.navigationController aWebViewController animated:NO];}
于 2013-07-01T11:25:33.943 回答