ASIHTTPRequest как переменная экземпляра и освобождение и освобождение - PullRequest
0 голосов
/ 11 ноября 2011
    "Informazioni.h file"
@interface Informazioni : UIViewController{
            .....
 ASIHTTRequest *mASIHTTPRequest;
}
@property (nonatomic, retain) ASIHTTRequest *mASIHTTPRequest;
----------------------------
#import "Informazioni.h"
#import "Globals.h"

@implementation Informazioni

@synthesize mImageViewImmagine;
            ....

@synthesize mASIHTTPRequest;


- (void)viewDidLoad {
[super viewDidLoad];
//start fetching based on id_prodotti
[self startFetch:mId_prodotto];
}


- (void) startFetch:(NSString *) pId_prodotto{
    //activate ASIHTTPDownloadCache

    NSURL *url = [NSURL URLWithString:[JSON_DESCRIZIONE stringByAppendingString:mId_prodotto]];//JSON_DATA

    mASIHTTPRequest = [ASIHTTPRequest requestWithURL:url];
    [mASIHTTPRequest setDelegate:self];
    [mASIHTTPRequest startAsynchronous];

}


- (void)loadDataWithOperation: (NSString *) responseString{
    NSLog(@"load data with operation");

    NSDictionary *tempDict = [[responseString JSONValue] objectForKey:@"descrizione_prodotto"];

    NSLog(@"descrizione_prodotto: %@",tempDict);



    [self.mTableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:YES];
    NSLog(@"reloadData called");


}



//start
- (void)requestFinished:(ASIHTTPRequest *)request{
    NSLog(@"SUCCESS Http fetching");

    // Operation Queue init (autorelease) 
    NSOperationQueue *queue = [NSOperationQueue new];
    // Create our NSInvocationOperation to call loadDataWithOperation, passing in nil
    NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self
                                                                            selector:@selector(loadDataWithOperation:)
                                                                              object:[request responseString]];
    // Add the operation to the queue
    [queue addOperation:operation];
    [operation release];


}

- (void)requestFailed:(ASIHTTPRequest *)request
{
    NSError *error = [request error];
    NSLog(@"%@",[error localizedDescription]);
    /*
     NSLog(@"Error: %@",[error localizedDescription]);
     UIAlertView *alert = [[UIAlertView alloc] 
     initWithTitle:@"DIUNAMAISHOP" 
     message:[error localizedDescription] 
     delegate:self 
     cancelButtonTitle:@"OK" 
     otherButtonTitles:nil];
     [alert show];
     [alert release];
     */
    /*
     //remove activity indicator
     if (self.mActivityIndicator.mFlag == YES) {
     [self.mActivityIndicator.view 
     performSelectorOnMainThread:@selector(removeFromSuperview) 
     withObject:nil waitUntilDone:YES];
     }
     */


}

-(void) queueFinished:(ASIHTTPRequest *) queue{
    //You could release the queue here if you wanted
    NSLog(@"Queue finished");
}
// end 

               ........

- (void)dealloc {
    //safely dealllocate

    [mASIHTTPRequest clearDelegatesAndCancel];
    [mASIHTTPRequest release];
              .....     
    [super dealloc];
    NSLog(@"Informazioni deallocated");
}


@end

Я просто выдвинул это представление, затем нажатие назад освободит / освободит контроллер представления .. - проблема в том, что он падает, когда я нажимаю назад во время выборки - как я могу преодолеть это любое предложение, сделанное tnx

1 Ответ

0 голосов
/ 11 ноября 2011
    mASIHTTPRequest = [ASIHTTPRequest requestWithURL:url];

Вы не сохраняете этот запрос. Вам нужно сохранить его, чтобы иметь действительную ссылку, чтобы затем можно было отменить и отпустить его. Либо добавьте сохранение, либо используйте self.mASIHTTPRequest.

...