【发布时间】:2012-02-12 07:27:12
【问题描述】:
我正在创建一个必须在 Mac OS X Tiger 上运行的 Mac 应用程序。由于某种奇怪的原因,它一直在崩溃。调试器返回以下错误:
0x90a594d1 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];
}
【问题讨论】:
-
“数据”如何定义,“字段”从何而来?
-
在头文件上。 NSMutableData *数据; IBOutlet NSTextField *field;
-
看不到任何可能导致崩溃的明显错误,抱歉,您必须尝试使用调试器进行更多跟踪。你真的不应该在 didReceiveResponse: 中分配数据,因为它可能会被多次调用。在 loadPage: 中执行此操作,只需在 didReceiveResponse 中将长度重置为 0。
标签: objective-c cocoa crash nsurlconnection osx-tiger