Hi friends I am getting images from webservice and loading these images in table view.But when i continue to scroll the program receives memory warning level1,level2 and then app exits with status 0.That happens only in device not in simulator.
Here is my code which i am putting please help me out.
- (void)viewDidLoad {
[super viewDidLoad];
UIButton *infoButton = [[UIButton alloc] initWithFrame:CGRectMake(0, -4, 62, 30)];
[infoButton setBackgroundImage:[UIImage imageNamed: @"back.png"] forState:UIControlStateNormal];
[infoButton addTarget:self action:@selector(backButtonClicked) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *customBarButtomItem = [[UIBarButtonItem alloc] initWithCustomView:infoButton];
self.navigationItem.leftBarButtonItem = customBarButtomItem;
[customBarButtomItem release];
[infoButton release];
UIButton *homeButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 62, 30)];
[homeButton setBackgroundImage:[UIImage imageNamed: @"home.png"] forState:UIControlStateNormal];
[homeButton.titleLabel setFont:[UIFont systemFontOfSize:11]];
//[homeButton setTitle:@"UPLOAD" forState:UIControlStateNormal];
[homeButton addTarget:self action:@selector(homeButtonClicked) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *rightBarButtom = [[UIBarButtonItem alloc] initWithCustomView:homeButton];
self.navigationItem.rightBarButtonItem = rightBarButtom;
[rightBarButtom release];
[homeButton release];
sellerTableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, 320, 416) style:UITableViewStylePlain];
sellerTableView.delegate=self;
sellerTableView.dataSource=self;
sellerTableView.backgroundColor=[UIColor clearColor];
sellerTableView.scrollEnabled=YES;
//table.separatorColor=[UIColor grayColor];
//table.separatorColor=[UIColor whiteColor];
//[[table layer]setRoundingMode:NSNumberFormatterRoundDown];
[[sellerTableView layer]setBorderColor:[[UIColor darkGrayColor]CGColor]];
[[sellerTableView layer]setBorderWidth:2];
//[[productTable layer]setCornerRadius:10.3F];
[self.view addSubview:sellerTableView];
appDel = (SnapItAppAppDelegate*)[[UIApplication sharedApplication] delegate];
}
-(void)viewWillAppear:(BOOL)animated
{
spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
spinner.center = self.view.center;
[self.view addSubview:spinner];
[spinner startAnimating];
[[SnapItParsing sharedInstance]assignSender:self];
[[SnapItParsing sharedInstance]startParsingForShowProducts:appDel.userIdString];
[sellerTableView reloadData];
}
-(void)showProducts:(NSMutableArray*)proArray
{
if (spinner) {
[spinner stopAnimating];
[spinner removeFromSuperview];
[spinner release];
spinner = nil;
}
if ([[[proArray objectAtIndex:1]objectForKey:@"Success"]isEqualToString:@"True"]) {
//[self.navigationController popViewControllerAnimated:YES];
//self.view.alpha=.12;
if (productInfoArray) {
[productInfoArray release];
}
productInfoArray=[[NSMutableArray alloc]init];
for (int i=2; i<[proArray count]; i++)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[productInfoArray addObject:[proArray objectAtIndex:i]];
NSLog(@"data fetch array is====> /n%@",productInfoArray);
[pool release];
}
}
}
#pragma mark (tableview methods)
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 100;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
//return [resultarray count];
return [productInfoArray count];
}
-(void)loadImagesInBackground:(NSNumber *)index{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSMutableDictionary *frame = [[productInfoArray objectAtIndex:[index intValue]] retain];
//NSLog(@"frame value ==>%@",[[frame objectForKey:@"Image"]length]);
NSString *frameImagePath = [NSString stringWithFormat:@"http://apple.com/snapit/products/%@",[frame objectForKey:@"Image"]];
NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:frameImagePath]];
NSLog(@"FRAME IMAGE%d",[[frame valueForKey:@"Image" ]length]);
if([[frame valueForKey:@"Image"] length] == 0){
NSString *imagePath = [[NSString alloc] initWithFormat:@"%@/%@",[[NSBundle mainBundle] resourcePath],@"no_image.png"];
UIImage *image = [UIImage imageWithContentsOfFile:imagePath];
[frame setObject:image forKey:@"friendImage"];
[imagePath release];
//[image release];
}
else {
//NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:frameImagePath]];
NSLog(@"image data length ==>%d",[imageData length]);
if([imageData length] == 0){
NSString *imagePath = [[NSString alloc] initWithFormat:@"%@/%@",[[NSBundle mainBundle] resourcePath],@"no_image.png"];
UIImage *image = [UIImage imageWithContentsOfFile:imagePath];
[frame setObject:image forKey:@"friendImage"];
[imagePath release];
//[image release];
}
else {
//UIImage *image = [[UIImage alloc] initWithData:imageData];
UIImage *image = [UIImage imageWithData:imageData];
[frame setObject:image forKey:@"friendImage"];
//[image release];
}
}
[frame release];
frame = nil;
[self performSelectorOnMainThread:@selector(reloadTable:) withObject:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:[index intValue] inSection:0]] waitUntilDone:NO];
[pool release];
}
-(void)reloadTable:(NSArray *)array{
NSLog(@"array ==>%@",array);
[sellerTableView reloadRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationNone];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *celltype=@"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:celltype];
for (UIView *view in cell.contentView.subviews) {
[view removeFromSuperview];
}
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"] autorelease];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.backgroundColor=[UIColor clearColor];
//cell.textLabel.text=[[resultarray objectAtIndex:indexPath.row] valueForKey:@"Service"];
/*UIImage *indicatorImage = [UIImage imageNamed:@"indicator.png"];
cell.accessoryView =
[[[UIImageView alloc]
initWithImage:indicatorImage]
autorelease];*/
/*NSThread *thread=[[NSThread alloc]initWithTarget:self selector:@selector() object:nil];
[thread setStackSize:44];
[thread start];*/
cell.backgroundView=[[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"cell.png"]]autorelease];
// [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"back.png"]] autorelease];
cell.selectionStyle=UITableViewCellSelectionStyleNone;
}
UIImageView *imageView= [[UIImageView alloc] initWithFrame:CGRectMake(19, 15, 75, 68)];
imageView.contentMode = UIViewContentModeScaleToFill;
// @synchronized(self)
//{
NSMutableDictionary *dict = [productInfoArray objectAtIndex:indexPath.row];
if([dict objectForKey:@"friendImage"] == nil){
imageView.backgroundColor = [UIColor clearColor];
if ([dict objectForKey:@"isThreadLaunched"] == nil) {
[NSThread detachNewThreadSelector:@selector(loadImagesInBackground:) toTarget:self withObject:[NSNumber numberWithInt:indexPath.row]];
[dict setObject:@"Yes" forKey:@"isThreadLaunched"];
}
}else {
imageView.image =[dict objectForKey:@"friendImage"];
}
//NSString *imagePath = [[NSString alloc] initWithFormat:@"%@/%@",[[NSBundle mainBundle] resourcePath],@"no_image.png"];
//imageView.layer.cornerRadius = 20.0;//vk
//imageView.image=[UIImage imageWithContentsOfFile:imagePath];
//imageView.layer.masksToBounds = YES;
//imageView.layer.borderColor = [UIColor darkGrayColor].CGColor;
//imageView.layer.borderWidth = 1.0;//vk
//imageView.layer.cornerRadius=7.2f;
[cell.contentView addSubview:imageView];
//[imagePath release];
[imageView release];
imageView = nil;
//}
UILabel *productCodeLabel = [[UILabel alloc] initWithFrame:CGRectMake(105, 7, 60,20 )];
productCodeLabel.textColor = [UIColor whiteColor];
productCodeLabel.backgroundColor=[UIColor clearColor];
productCodeLabel.text=[NSString stringWithFormat:@"%@",@"Code"];
[cell.contentView addSubview:productCodeLabel];
[productCodeLabel release];
UILabel *CodeValueLabel = [[UILabel alloc] initWithFrame:CGRectMake(170, 7, 140,20 )];
CodeValueLabel.textColor = [UIColor whiteColor];
CodeValueLabel.backgroundColor=[UIColor clearColor];
CodeValueLabel.text=[NSString stringWithFormat:@"%@",[[productInfoArray objectAtIndex:indexPath.row]valueForKey:@"ID"]];
[cell.contentView addSubview:CodeValueLabel];
[CodeValueLabel release];
UILabel *productNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(105, 35, 60,20 )];
productNameLabel.textColor = [UIColor whiteColor];
productNameLabel.backgroundColor=[UIColor clearColor];
productNameLabel.text=[NSString stringWithFormat:@"%@",@"Name"];
[cell.contentView addSubview:productNameLabel];
[productNameLabel release];
UILabel *NameValueLabel = [[UILabel alloc] initWithFrame:CGRectMake(170, 35, 140,20 )];
NameValueLabel.textColor = [UIColor whiteColor];
NameValueLabel.backgroundColor=[UIColor clearColor];
NameValueLabel.text=[NSString stringWithFormat:@"%@",[[productInfoArray objectAtIndex:indexPath.row]valueForKey:@"Title"]];
[cell.contentView addSubview:NameValueLabel];
[NameValueLabel release];
UILabel *dateLabel = [[UILabel alloc] initWithFrame:CGRectMake(105, 68, 60,20 )];
dateLabel.textColor = [UIColor whiteColor];
dateLabel.backgroundColor=[UIColor clearColor];
dateLabel.text=[NSString stringWithFormat:@"%@",@"Date"];
[cell.contentView addSubview:dateLabel];
[dateLabel release];
UILabel *dateValueLabel = [[UILabel alloc] initWithFrame:CGRectMake(170, 68, 140,20 )];
dateValueLabel.textColor = [UIColor whiteColor];
dateValueLabel.backgroundColor=[UIColor clearColor];
dateValueLabel.text=[NSString stringWithFormat:@"%@",[[productInfoArray objectAtIndex:indexPath.row]valueForKey:@"PostedDate"]];
dateValueLabel.font=[UIFont systemFontOfSize:14];
dateValueLabel.numberOfLines=3;
dateValueLabel.adjustsFontSizeToFitWidth=YES;
[dateValueLabel setLineBreakMode:UILineBreakModeCharacterWrap];
[cell.contentView addSubview:dateValueLabel];
[dateValueLabel release];
}
Please-2 help me out ,where i am doing mistake.....