2012-02-12 186 views
2

我正在創建一個必須在Mac OS X Tiger上運行的Mac應用程序。出於一些奇怪的原因,它不斷崩潰。調試器返回以下錯誤:NSURLConnection奇怪的崩潰

0x90a594d1 <+0033> mov (%edi,%edx,4),%eax

我試過谷歌的答案,但我什麼也沒找到。我究竟做錯了什麼?

-(IBAction)loadPage:(id)sender{ 
    NSURL *URL = [NSURL URLWithString:@"http://www.google.com"]; 
    [NSURLConnection connectionWithRequest:[NSURLRequest requestWithURL:URL] delegate:self]; 
    NSLog(@"STARTED!"); 
} 

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{ 
    NSLog(@"STARTED!2"); 
    data = [[NSMutableData alloc]init]; 
} 

-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)d{ 
    NSLog(@"STARTED!3"); 
    [data appendData:d]; 
} 

- (void)connectionDidFinishLoading:(NSURLConnection *)connection{ 

    NSLog(@"STARTED!4"); 
    NSString *str = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; 
    NSLog(@"%@", str); 

    [webView loadHTMLString:str baseURL:[NSURL URLWithString:[field stringValue]]]; 

    [str release]; 
    [data release]; 
} 
+0

如何「數據」所定義,哪裏「田」從何而來? – 2012-02-12 07:31:09

+0

在頭文件上。 NSMutableData *數據; IBOutlet NSTextField *字段; – 2012-02-12 07:38:28

+0

不能真正看到任何明顯的錯誤,可能會導致崩潰,對不起,認爲你將不得不嘗試使用調試器追蹤更多。你真的不應該在didReceiveResponse中分配數據:儘管它可能被多次調用。在loadPage中執行:相反,只需在didReceiveResponse中將長度重置爲0即可。 – 2012-02-12 08:04:02

回答

1

的解決方案是保留NSURLConnection的