我加载带有图像的表格并向上和向下滚动。大约一分钟后,我收到“收到内存警告”通知。在看到此消息几次后,应用程序崩溃了。
每次用户滚动到表格底部时,我会通过滚动位置5图像来加载。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"aCell";
PostTable_Cell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
CGFloat cellHeight = (screenWidth / 16) * 10 + self.view.frame.size.height * 0.09;
cell = [[PostTable_Cell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier withParentWidth:self.view.frame.size.width withCellHeight:cellHeight withParent:self withPostArray:[postsArray objectAtIndex:indexPath.row] withCurrentIndexPostArray:(int)indexPath.row];
[cell setUserInteractionEnabled:YES];
cell.selectionStyle = UITableViewCellStyleDefault;
tableView.separatorColor = [UIColor blackColor];
return cell;
}
编辑:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"aCell";
PostTable_Cell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
CGFloat cellHeight = (screenWidth / 16) * 10 + self.view.frame.size.height * 0.09;
if (cell == nil)
{
cell = [[PostTable_Cell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier withParentWidth:self.view.frame.size.width withCellHeight:cellHeight withParent:self withPostArray:[postsArray objectAtIndex:indexPath.row] withCurrentIndexPostArray:(int)indexPath.row];
[cell setUserInteractionEnabled:YES];
cell.selectionStyle = UITableViewCellStyleDefault;
tableView.separatorColor = [UIColor blackColor];
}
else
{
[cell reloadCellContetWithParent:self withPostArray:[postsArray objectAtIndex:indexPath.row] withCurrentIndexPostArray:(int)indexPath.row];
}
return cell;
}
编辑3:
@implementation PostTable_Cell
- (void)awakeFromNib
{
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
-(void)dealloc
{
#ifdef DEBUG
NSLog(@"%@ destoyed",NSStringFromClass([self class]));
#endif
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier withParentWidth:(CGFloat)parentWidth withCellHeight:(CGFloat)celltHeight withParent:(id)parent withPostArray:(id)postArray withCurrentIndexPostArray:(int)IndexNumber
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self)
{
mainDalegate = (Main*)parent;
self.backgroundColor = [UIColor clearColor];
Post *curPost = (Post*)postArray;
postId = [curPost getPostId];
postText = [curPost getPostText];
postImageUrl = [curPost getImageUrl];
commentsCount = [curPost getCommentsCount];
likesCount = [curPost getLikesCount];
likeByMe = [curPost getLikeByMe];
facebookId = [curPost getCreatorFacebookId];
publisherName =[curPost getCreatorName];
currentIndexPostArray = IndexNumber;
[GeneralMethods setNew_width:parentWidth ToView:self];
[GeneralMethods setNew_height:celltHeight ToView:self];
[self cellBuilderForPost];
}
return self;
}
答案 0 :(得分:0)
mainDalegate = (Main*)parent;
看起来这可能是你的问题。由于您正在创建保留周期,因此您的单元格不会被释放。
rules to avoid retain cycles。