我正在使用启用了 ARC 的 xcode 4.6。我想从服务器向 UItableview 行添加一些图像。我收到如下错误:
malloc:* 对象 0xa2b6f50 的错误:未分配被释放的指针 *在 malloc_error_break 中设置断点以进行调试
这是我的代码:
NSURL *imageURL = [NSURL URLWithString:[templateURL stringByAppendingFormat:@"%@",[[templateArray objectAtIndex:i] objectForKey:@"options_picture"]]];
UIImageView *templateView=[[UIImageView alloc]initWithFrame:CGRectMake(x1, y1, wid, ht)];
NSLog(@"templeteArray %@",imageURL);
AsyncronousUIImage *image=[[AsyncronousUIImage alloc]init];
[image loadImageFromURL:imageURL inImageView:templateView];
image.delegate=self;
[templateScroll addSubview:templateView];
AsyncronousUIImage 类如下:
- (void)loadImageFromURL:(NSURL *)anUrl inImageView:(UIImageView*)imgView{
imageView = imgView;
NSURLRequest *request = [NSURLRequest requestWithURL:anUrl
cachePolicy:NSURLRequestReturnCacheDataElseLoad
timeoutInterval:30.0];
connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];}
- (void)connection:(NSURLConnection *)theConnection didReceiveData:(NSData *)incrementalData {
if (data == nil)
data = [[NSMutableData alloc] initWithCapacity:2048];
[data appendData:incrementalData];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)theConnection
{
[self initWithData:data];
data = nil;
connection = nil;
[self.delegate imageDidLoad:self];
}
任何帮助表示赞赏。