我目前正試圖從互聯網加載圖像。這是我做什麼(我把它從蘋果的LazyTableImages演示項目):從URL加載UIImage時發生奇怪的崩潰
#pragma mark - Download
- (void)startImageDownload
{
activeDownload = [[NSMutableData alloc] init];
// alloc+init and start an NSURLConnection; release on completion/failure
NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:NSURLRequest requestWithURL:[NSURL URLWithString:@"http://pixelpainter.wannerbrothers.net/images/5.png"]] delegate:self];
imageConnection = conn;
[conn release];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[activeDownload appendData:data];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
// Clear the activeDownload property to allow later attempts
activeDownload = nil;
// Release the connection now that it's finished
imageConnection = nil;
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
UIImage *_image = [[UIImage alloc] initWithData:activeDownload];
image_.image = _image;
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[self startImageDownload];
[super viewDidLoad];
}
在的情況下,圖像加載約50%,一切工作正常。但大多數情況下,應用程序只是崩潰而沒有任何線索(沒有引發NSException),它只是得到一個SIGABRT。 可能是什麼問題?謝謝!
你能告訴我們它崩潰? – edo42 2011-05-24 15:22:25
爲什麼不在調試器下運行該程序,以便正確地看到有問題的語句和堆棧跟蹤。 – sergio 2011-05-24 15:23:30
有時,它在main()函數中崩潰,有時在「objc_msgSend_disassembly_0x015ca0b0.nasm」 – 2011-05-24 16:02:30