2011-11-11 1 views
-1
"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 

я просто толкнул эту точку зрения, то нажатие обратно будет dealloc/отпустить ViewController .. - проблема он выходит из строя, когда я нажимаю назад во время его извлечения - как я преодолевать это любое предложение сделает tnxASIHTTPRequest в качестве переменной экземпляра и deallocating и отпуская

ответ

0
mASIHTTPRequest = [ASIHTTPRequest requestWithURL:url]; 

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

+0

видa подобный это? 'self.mASIHTTPRequest = [ASIHTTPRequest requestWithURL: url]; [self.mASIHTTPRequest setDelegate: self]; [self.mASIHTTPRequest startAsynchronous]; ' как насчет dealloc следует также добавить self.mASIHTTPRequest' [self.mASIHTTPRequest clearDelegatesAndCancel]; [self.mASIHTTPRequest release]; ' tnx для быстрого ответа, к сожалению, я не могу проверить код до понедельника .. плохо обновить после проверки. – user966337

+0

'self.mASIHTTPRequest = [ASIHTTPRequest requestWithURL: url];' будет делать это; не нужно ничего менять – JosephH

+0

спасибо, что это работает ..! я думал, что он будет работать без «я». Потому что я предполагаю, что они будут работать без него. – user966337