2011-11-11 41 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 /釋放視圖控制器.. - 問題是,當我按下背部,同時它取 崩潰 - 我怎樣才能克服這個任何建議將做tnxASIHTTPRequest作爲實例變量和釋放,釋放

回答

0
mASIHTTPRequest = [ASIHTTPRequest requestWithURL:url]; 

你不保留這個請求。您需要保留它以具有有效的參考引用,然後才能取消並釋放它。要麼添加一個保留,要麼使用self.mASIHTTPRequest。

+0

有點像這樣嗎? 'self.mASIHTTPRequest = [ASIHTTPRequest requestWithURL:url]; [self.mASIHTTPRequest setDelegate:self]; [self.mASIHTTPRequest startAsynchronous];' 怎麼樣dealloc我也應該添加self.mASIHTTPRequest'[self.mASIHTTPRequest clearDelegatesAndCancel]; [self.mASIHTTPRequest發佈];' tnx爲快速回復可悲我不能測試代碼,直到星期一..虐待更新一次我測試。 – user966337

+0

'self.mASIHTTPRequest = [ASIHTTPRequest requestWithURL:url];'會做;無需改變任何其他 – JosephH

+0

謝謝它的作品..!我認爲它會在沒有'self.'的情況下工作,因爲我認爲它們在沒有它的情況下工作是一樣的。 – user966337