I am a beginner in iPhone programming... I have an application that's like a photo gallery where I am loading the images and title for each cell in the UITableView using a server with JSON. When I scroll the table the program crashes!
-(NSInteger) tableView : (UITableView *) tableView numberOfRowsInSection:(NSInteger) section {
return [id_arr count];
}
-(CGFloat) tableView : (UITableView *) tableView heightForRowAtIndexPath: (NSIndexPath *) indexPath {
return 80;
}
//
// tableView:cellForRowAtIndexPath:
//
// Returns the cell for a given indexPath.
//
- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
NSString *tmp3=[NSString stringWithFormat:@"%@",[path_arr objectAtIndex:indexPath.row]];
tmp3=[tmp3 stringByReplacingOccurrencesOfString:@"(" withString:@""];
tmp3=[tmp3 stringByReplacingOccurrencesOfString:@")" withString:@""];
tmp3=[tmp3 stringByReplacingOccurrencesOfString:@" " withString:@""];
tmp3=[tmp3 stringByReplacingOccurrencesOfString:@"\n" withString:@""];
NSLog(@"URL:%@",tmp3);
NSData *imageData = [[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:tmp3]];
//NSLog(@"Image DATA:%@",[path_arr objectAtIndex:0]);
UIImage* image1 = [[UIImage alloc] initWithData:imageData];
UIImageView *imgview=[[UIImageView alloc]initWithImage:image1];
imgview.frame=CGRectMake(5, 5, 56, 68);
imgview.backgroundColor=[UIColor redColor];
[cell.contentView addSubview:imgview];
UILabel *lbl_desc=[[UILabel alloc]initWithFrame:CGRectMake(70, 1, 240, 50)];
NSString *tmp=[NSString stringWithFormat:@"%@",[descrip_arr objectAtIndex:indexPath.row]];
tmp=[tmp stringByReplacingOccurrencesOfString:@"(" withString:@""];
tmp=[tmp stringByReplacingOccurrencesOfString:@")" withString:@""];
tmp=[tmp stringByReplacingOccurrencesOfString:@"\n" withString:@""];
//tmp=[tmp stringByReplacingOccurrencesOfString:@" " withString:@""];
lbl_desc.text=tmp;
lbl_desc.font=[UIFont systemFontOfSize:14];
lbl_desc.lineBreakMode=UILineBreakModeWordWrap;
lbl_desc.numberOfLines=0;
lbl_desc.textAlignment=UITextAlignmentLeft;
lbl_desc.backgroundColor=[UIColor clearColor];
[cell.contentView addSubview:lbl_desc];
NSLog(@"A_count:%@",[count_arr objectAtIndex:0]);
UILabel *lbl_page=[[UILabel alloc]initWithFrame:CGRectMake(230, 50, 100, 20)];
NSString *tmp1=[NSString stringWithFormat:@"%@",[count_arr objectAtIndex:indexPath.row]];
NSLog(@"A_count1:%@",tmp1);
tmp1=[tmp1 stringByReplacingOccurrencesOfString:@"(" withString:@""];
tmp1=[tmp1 stringByReplacingOccurrencesOfString:@")" withString:@""];
tmp1=[tmp1 stringByReplacingOccurrencesOfString:@"\n" withString:@""];
tmp1=[tmp1 stringByAppendingString:@" Images"];
NSLog(@"A_count123:%@",tmp1);
lbl_page.text=tmp1;
lbl_page.font=[UIFont systemFontOfSize:12];
lbl_page.lineBreakMode=UILineBreakModeWordWrap;
lbl_page.numberOfLines=0;
lbl_page.textAlignment=UITextAlignmentLeft;
lbl_page.backgroundColor=[UIColor clearColor];
[cell.contentView addSubview:lbl_page];
cell.backgroundColor=[UIColor clearColor];
[imageData release];
[image1 release];
[imgview release];
}