Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/119.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 当TableView重新加载数据时,cpu使用率急剧上升_Ios_Uitableview_Cpu_Cpu Usage_Reloaddata - Fatal编程技术网

Ios 当TableView重新加载数据时,cpu使用率急剧上升

Ios 当TableView重新加载数据时,cpu使用率急剧上升,ios,uitableview,cpu,cpu-usage,reloaddata,Ios,Uitableview,Cpu,Cpu Usage,Reloaddata,我有一个复杂的表格视图,它的单元格有很多内容 当我重新加载数据我的表格视图时,cpu使用率迅速上升,甚至达到180% 所以,在实际设备中,5c或5s,应用程序将崩溃,我认为这是因为cpu使用导致应用程序崩溃 那么,有没有一种方法可以限制cpu的使用或者让应用程序不崩溃呢 添加-1 我不认为tableView委托方法对这个问题有帮助,但我还将介绍其中的一部分: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRow

我有一个复杂的
表格视图
,它的单元格有很多内容

当我
重新加载数据
我的
表格视图
时,cpu使用率迅速上升,甚至达到180%

所以,在实际设备中,
5c
5s
,应用程序将崩溃,我认为这是因为cpu使用导致应用程序崩溃

那么,有没有一种方法可以限制cpu的使用或者让应用程序不崩溃呢


添加-1

我不认为
tableView委托方法
对这个问题有帮助,但我还将介绍其中的一部分:

- (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;
}
lmlagragiculturetechcell.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;
//未获取时间 [_timesizetofit]

// 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];

}

是否每次加载单元格时都在tableviewcell中使用
[NSURL URLWithString:model.lml_iconName]
下载图像?模拟器运行时间不一定等于设备运行时间。1) 它是在一个完全不同的体系结构上模拟的(x64 vs ARM)2)在Xcode和模拟器之间运行各种调试代码。在设备上运行,看看是否有问题。如果你真的这样做了,那么就用仪器来分析并找出问题所在。在模拟环境中基于调试运行时进行优化是毫无意义的。@Josh Homann,但在我的真实设备中,它会崩溃,cpu使用率也很高。@KrishnaCA Hi,bro。我使用
SDWebImage
,您会看到这一行:
[\u iconView sd\u setImageWithURL:[NSURL URLWithString:model.lml\u iconName]占位符图像:img\u占位符\u圈头]