When TableView reloadData, the cpu usage rise violently

248 views Asked by At

I have a complex tableView, which's cell have many contents.

enter image description here

And when I reloadData my tableView, the cpu usage raise up quickly, even to 180%!

enter image description here

So, in real device, 5c or 5s, the app will crash, I think is because the cpu usage the app crash.

So, is there a method to limit the cpu usage or let app do not crash?


Addition-1

I don't think the tableView delegate methods is help for the question ,but I will also put part of them:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:exp_TableIdentifier]; 

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

    ((LMLAgricultureTechCell *)cell).model = self.help_dataSource[indexPath.row];
    ((LMLAgricultureTechCell *)cell).indexPath = indexPath;
    ((LMLAgricultureTechCell *)cell).delegate = self;
    ((LMLAgricultureTechCell *)cell).photo_view.delegate = self;

    // solve SDWebImage memory increase
    SDImageCache *imageCache = [SDImageCache sharedImageCache];
    [imageCache clearMemory];

    return cell;
}

In the LMLAgricultureTechCell.m:

- (void)setModel:(LMLAgricultureTechModel *)model{

_model = model;

_shouldOpenContentLabel = NO;

// 1.头像
_iconView.image = [UIImage imageNamed:model.lml_iconName];
[_iconView sd_setImageWithURL:[NSURL URLWithString:model.lml_iconName] placeholderImage:img_placeholder_circle_header];
[Util roundBorderView:_iconView.bounds.size.width / 2.0 border:0 color:nil view:_iconView];
// 2.名字
_nameLabel.text = model.lml_userName == nil || [model.lml_userName  isEqual: @""] || [model.lml_userName isEqual:[NSNull null]] ? @"" : model.lml_userName;  // 未获得用户名
// 防止单行文本Label在重新用的时候宽度计算不准的问题
[_nameLabel sizeToFit];
// 3.地址
_loacation.text = model.lml_location == nil || [model.lml_location  isEqual: @""] || [model.lml_location isEqual:[NSNull null]] ? @"" : [model.lml_location componentsSeparatedByString:@"-"].lastObject;  //未获得地址

// 4.时间
_time.text = model.lml_time == nil  || [model.lml_time  isEqual: @""] || [model.lml_time isEqual:[NSNull null]] ? @"" : model.lml_time;

// 未获取时间 [_time sizeToFit];

// 5.标题
_title.text = model.lml_title == nil  || [model.lml_title  isEqual: @""] || [model.lml_title isEqual:[NSNull null]] ? @"" : model.lml_title;  //未获得标题

//[_title sizeToFit];

// 6.内容
_content.text = model.lml_content;
_photo_view.picPathStringsArray = model.lml_imagesArr;


// 7.如果文字高度超过60
if (model.shouldShowMoreButton) {
    _allContent.sd_layout.heightIs(20);
    _allContent.hidden = NO;
    // 如果需要展开
    if (model.isOpening) {
        _content.sd_layout.maxHeightIs(MAXFLOAT);
        [_allContent setTitle:NSLocalizedString(@"收起", nil) forState:UIControlStateNormal];
    }else {
        _content.sd_layout.maxHeightIs(maxContentLabelHeight);
        [_allContent setTitle:NSLocalizedString(@"全文", nil) forState:UIControlStateNormal];
    }
}else {

    _allContent.sd_layout.heightIs(0);
    _allContent.hidden = YES;
}


if (model.isMyPost) {

    _delete.sd_layout.heightIs(20).widthIs(40);
    _delete.hidden = NO;
}else {

    _delete.sd_layout.heightIs(0);
    _delete.hidden = YES;
}

// 8.现在判断allOrDelete back
if (_allContent.hidden == YES && _delete.hidden == YES) {
    _allAndDeleteView.sd_layout.heightIs(0);
}else {

    _allAndDeleteView.sd_layout.heightIs(20);
}

// 9.图片数组
CGFloat picContainerTopMargin = 0;
if (model.lml_imagesArr.count) {
    picContainerTopMargin = 10;
}
_photo_view.sd_layout.topSpaceToView(_allAndDeleteView, picContainerTopMargin);
_photo_view.picPathStringsArray = model.lml_imagesArr;

_showCountlabel.text = model.lml_scanTimes;
_goodImageView.image = model.lml_isLiked ? [UIImage imageNamed:@"pre_list_thumb_selected.png"]:[UIImage imageNamed:@"pre_list_thumb"];
_goodCountlabel.text = model.lml_likeTimes;
_speakCountlabel.text = model.lml_commentTimes;

  // 底部的
_bottomView = part3;

[self setupAutoHeightWithBottomView:_bottomView bottomMargin:15];

}
0

There are 0 answers