2015-12-02 80 views
1

我加载一个包含图像的表格并上下滚动。一分钟左右后,我收到“收到内存警告”通知。几次看到此消息后,该应用程序崩溃。收到的内存警告在UITableView中

每当用户滚动到表格底部时,我都会通过滚动位置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; 
} 
+1

很明显,您的图片没有发布。你需要展示一些代码给任何人来帮助你。特别是你的“cellForRowAtIndexPath”会有帮助 – ullstrm

+0

你是否一次加载所有的表? –

+0

我编辑问题。 –

回答

0

mainDalegate = (Main*)parent; 看起来这可能是您的问题。您的单元格不会被释放,因为您正在创建一个保留循环。 rules to avoid retain cyclesenter image description here