iOS - 应用程序在iOS 10上更新后变得迟钝

时间:2016-12-16 09:29:40

标签: ios

我创建了一个应用程序,我在其中一个Dashboard中使用了UICollection View。我的应用程序在iOS版本8,9中运行顺利,但是当我在iOS 10或更高版本上运行时,应用程序变得很慢。我在Xcode乐器中使用Time profiler来检查应用程序在哪个时间点占用最多时间。

我发现[scrollCollectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath]需要花费太多时间。

请告诉任何人是否有解决我问题的方法。 我的代码是: -

- (UICollectionViewCell *)collectionView:(UICollectionView *)scrollCollectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{

    static NSString *identifier  = @"Cell";

    CollectionViewCell *cell = (CollectionViewCell*)[scrollCollectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];


    RigObject *object = [rigData objectAtIndex:indexPath.row];
    cell.rigNumber.text = [NSString stringWithFormat:@"%@",object.rigNumber];
    cell.rigTemp.text = object.rigTemp;
    cell.rigTimer.text = object.rigTimer;
    cell.slotUsed.text = object.slotUsed;
    cell.slotFree.text = object.slotFree;
    cell.rigStatus.text = object.rigStatus;
    cell.shockType.text = object.shockType;
    cell.totalTask.text = object.completedTask;
    cell.pendingTask.text = object.pendingTask;
    NSTimeInterval interval = [[NSDate date] timeIntervalSinceDate:object.updatedDate]/3600;
    if (interval < 8) {
        cell.rigTimer.textColor = [UIColor greenColor];
    }
    else if (interval > 8 && interval < 16) {
        cell.rigTimer.textColor = [UIColor orangeColor];
    }
    else if ( interval > 16) {
        cell.rigTimer.textColor = [UIColor redColor];
    }
    if ([object.rigStatus isEqualToString:@"Not Working"]) {
        cell.rigView.layer.borderWidth = 2;
        cell.rigView.layer.borderColor = [[UIColor redColor]CGColor];

        [cell.rigStatus setTextColor:[UIColor redColor]];
    }
    else
    {
        cell.rigView.layer.borderWidth = 0;
        [cell.rigStatus setTextColor:[UIColor colorWithRed:0.0491 green:0.4404 blue:0.1049 alpha:1]];
    }

    cell.tripDescription.tag=indexPath.row;
    [cell.tripDescription addTarget:self
               action:@selector(tripDescriptionClicked:) forControlEvents:UIControlEventTouchUpInside];

    cell.rigView.contentMode = UIViewContentModeScaleAspectFit;


    return cell;
}

0 个答案:

没有答案