views:

45

answers:

2

i am using a navigation controller in my application.... this app gets the current gps location of device and according to which it shows results from a web page(coffee shops near that place)..

all works fine but during the request if the user click navigation back button my app. shows error... i know this error is about web request ....

(NOTE--i don't want to disable navigation back button)

is it possible that when user click back button the corresponding web request also stop? if yes please help and provide code if possible..... Thank You

UPDATE-----------------

some of my code is this code is for getting name of current place...

NSString *urlString = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%@&output=csv", 
   [NSString stringWithFormat:@"%f,%f",mUserCurrentLocation.coordinate.latitude, mUserCurrentLocation.coordinate.longitude]];
NSString *locationString = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlString]];
NSArray *listItems = [locationString componentsSeparatedByString:@"\""];

.....my app work fine if user does not click back button during the process..

+1  A: 

It depends on what your code looks like. Please post some to clarify your question.

Whenever I try to download something from within my web application, I use a asynchronous call. That way when a method is ready, it will call some kind of "Request Done" method. In there you can check if the view is still active or not.

Your code probably tries to use some UI elements that are already released when the user clicks back and your web-request finishes after that.

Wim Haanstra
i have edited my code please help
Ranjeet Sajwan
In the code you posted you don't do your web request. Right? Try looking at the documentation for NSURLConnection
Wim Haanstra
this code is for getting name of that place
Ranjeet Sajwan
Yeah but getting the URL probably isn't the problem. The problem is that your request finishes when the user already navigated away from the view.
Wim Haanstra
+1  A: 

I assume that you have put your UIWebView on a UIViewController which is again a part of UINavigationController hierarchy. And the back-button which you've reference in your question is the default back button item in left.

With this assumption following code would be useful:

- (void)viewWillDisappear:(BOOL)animated {
    if ([self.navigationController.viewControllers indexOfObject:self] == NSNotFound) {
        if ([webView isLoading])
            [webview stopLoading];
    }

    [super viewWillDisappear:animated];
}

And webView is the instance of UIWebView.

Thanks, Sagar.

Sagar
thanks for answer... and sorry for delay.....voted and accepted...
Ranjeet Sajwan