简体   繁体   English

UITableView中的大量内存使用情况

[英]Much memory usage in UITableView

I have an UITableViewController and I customize its UITableViewCell s. 我有一个UITableViewController并且自定义了它的UITableViewCell Each UITableViewCell contains two UIImageViews and two UILabel s. 每个UITableViewCell包含两个UIImageViews和两个UILabel Although when I get into the UITableView the memory usage raises to 100 MB and i do not know the reason. 虽然当我进入UITableView ,内存使用量增加到100 MB,但我不知道原因。 Here is the code for the cellForRowAtIndexPath method that handles the cell customization. 这是处理单元格自定义的cellForRowAtIndexPath方法的代码。 Can anyone help me with this issue? 谁能帮我解决这个问题?

- (UITableViewCell *)tableView:(UITableView *)tableView 
         cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    static NSString *simpleTableIdentifier = @"Cell";

    UITableViewCell *cell = 
      [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
                                      reuseIdentifier:simpleTableIdentifier];
    }   

    UILabel *mnhmeioLabel = (UILabel *)[cell viewWithTag:102]; 
    mnhmeioLabel.frame = CGRectMake(mnhmeioLabel.frame.origin.x,  
                                    mnhmeioLabel.frame.origin.y, 
                                    191, 
                                    21);

    Group *tmpGroup = [mnhmeiaTotal objectAtIndex:indexPath.row];
    NSLog(@"%@ ",tmpGroup.title);    
    NSLog(@"%f %f", mnhmeioLabel.bounds.size.width, 
                    mnhmeioLabel.bounds.size.height);

    mnhmeioLabel.text = tmpGroup.title;
    mnhmeioLabel.font = [UIFont fontWithName:@"Open Sans" size:10];    
    mnhmeioLabel.numberOfLines=0;
    mnhmeioLabel.lineBreakMode=NSLineBreakByWordWrapping;    
    [mnhmeioLabel sizeToFit];   

    if( tmpGroup.imagesOfArticle.count > 0 ){
        UIImageView *mnhmeioImageView = (UIImageView *)[cell viewWithTag:103];
        mnhmeioImageView.image = [tmpGroup.imagesOfArticle objectAtIndex:0];
    } else {
        UIImageView *mnhmeioImageView = (UIImageView *)[cell viewWithTag:103];
        mnhmeioImageView.image = [UIImage imageNamed:@""];
    }    

    UIImageView *markerImageView=(UIImageView *)[cell viewWithTag:100];
    markerImageView.image=[self selectMarker:tmpGroup];

    UILabel *mnhmeioDescription = (UILabel *)[cell viewWithTag:101];
    mnhmeioDescription.text=tmpGroup.constructedContent;

    mnhmeioDescription.font = [UIFont fontWithName:@"Open Sans" size:6];    
}

Probably, the images are big. 图片可能很大。

Or, perhaps you are not reusing the cells properly, if you are using iOS7 and Storyboards, please follow this tutorial (Prototype cells and Using subclass for a cell sections): http://www.raywenderlich.com/50308/storyboards-tutorial-in-ios-7-part-1 或者,也许您没有正确地重用单元格,如果您使用的是iOS7和Storyboards,请遵循此教程(原型单元格和使用子类的单元格部分): http ://www.raywenderlich.com/50308/storyboards-tutorial -在ios-7-part-1中

Thank you all for your help. 谢谢大家的帮助。 I had to decrease the size of each image as much as i could. 我不得不尽可能地减小每个图像的大小。 This fixed my problem. 这解决了我的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM