Reputation: 19956
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
PostCount *post=[listArr objectAtIndex:indexPath.row];
//NSString *CellIdentifier = [NSString stringWithFormat: @"Cell%d_%d_%@_%d",indexPath.section,indexPath.row,post.foreignId,[listArr count]];
NSString *CellIdentifier = [NSString stringWithFormat: @"Cell_%d_%@",indexPath.row,post.foreignId];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
NSLog(@"indexPath.row++++++++=%d",indexPath.row);
TimeLineGraphicView *gview=[[TimeLineGraphicView alloc]init];
gview.tag=indexPath.row+1000;
gview.delegate=self;
[cell addSubview:gview];
int Allheight =[ModelClass returnGraphicViewHeight_timeLine:post];
gview.frame=CGRectMake(0, 0, 320, Allheight);
[gview setViewStyle:post];
}
TimeLineGraphicView *gview=(TimeLineGraphicView *)[cell viewWithTag:indexPath.row+1000];
gview.lab_time.text=[ModelClass intervalSinceNow:post.when btime:0];
//NSLog(@"intervalSinceNow=%@ ",[ModelClass intervalSinceNow:post.when btime:0]);
//NSLog(@"post.when=%@ gview=%@ gview.lab_time.text=%@",post.when,gview, gview.lab_time.text);
return cell;
}
hello,if i use the above code if i have many cell, TimeLineGraphicView *gview=[[TimeLineGraphicView alloc]init] can increase memory,because when i load many cell for example first i load 15 cell,then add 15 cell then add 15 cell and so on,it give me didReceiveMemoryWarning,can you good practice to deal with the problem
Upvotes: 0
Views: 95
Reputation: 1938
The way you are implementing the things are not right.
– cellForRowAtIndexPath:
you can just create it and set the data.!I think if you implement things in the proper way, tableview should not show any memory warning no matter how many lines there are..!
If you are still unclear on customizing tableViewCells, just google it, you will find tons of tutorials.
Good luck..!
Upvotes: 1
Reputation: 21726
You do not release the cell
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
You do not release the view
[cell addSubview:gview];
[gview release];
Upvotes: 1