ios - 提高核心情节的表现

标签 ios xcode ipad plot core-plot

我正在使用 CorePlot 库绘制实时心电图。当它在 iPad air 中使用时,性能还可以。但是当我尝试时它与 iPad mini,绘图有延迟。我已经完成了 collapseLayer 和 this link也。这并没有解决我的问题。任何人都可以为此提出新的解决方案。

我的代码如下:

-(void)newData:(NSTimer *)theTimer
{

    for (int i =0;i<plotcount;i++){

        if([Qrrch0 count]>0 || [Qrrch1 count]>0 || [Qrrch2 count]>0 || [Qrrch3 count]>0 || [Qrrspo2 count]>0 ){

            if(g1==1 && thePlot){

                currentIndex ++;
            }
            if(g2==1 && thePlot1){
                currentIndex1 ++;
            }
            if(g3==1 && thePlot2){
                currentIndex2 ++;
            }
            if(g4==1 && thePlot3){
                currentIndex3 ++;
            }
            if(spo2==1 && thePlot4){
                currentIndex4 ++;
            }

            if(arrayIndex>=kchannel1-1)
            {
                arrayIndex=0;
            }

            if(arrayIndex1>=kchannel2-1)
            {
                arrayIndex1=0;
            }
            if(arrayIndex>=kchannel1-1)
            {
                arrayIndex=0;
            }
            if(arrayIndex2>=kchannel3-1)
            {
                arrayIndex2=0;
            }

            if(arrayIndex3>=kchannel4-1)
            {
                arrayIndex3=0;
            }

            if(arrayIndex4>=kchannel5-1)
            {
                arrayIndex4=0;
            }




            if(g1==1 && thePlot){
                 currentIndex5++;
                if(currentIndex5>=kchannel1)
                {
                    if(arrayIndex==0)
                    {
                        [thePlot reloadDataInIndexRange:NSMakeRange(arrayIndex, arrayIndex)];
                    }else{
                  [thePlot deleteDataInIndexRange:NSMakeRange(arrayIndex, 1)];


                    }
                }
                if([Qrrch0 count]!=0)
                {

                    arrPlot[arrayIndex]=[[Qrrch0 objectAtIndex:0] integerValue];

                    lastPlot0=[Qrrch0 objectAtIndex:0];

                }else{
                    arrPlot[arrayIndex]=[lastPlot0 integerValue];

                }
                   arrayIndex++;
            }
            if(g2==1 && thePlot1){
                currentIndex6++;
                if(currentIndex6>=kchannel2)
                {
                    if(arrayIndex1==0)
                    {
                        [thePlot1 reloadDataInIndexRange:NSMakeRange(arrayIndex1, arrayIndex1)];
                    }else{
                        [thePlot1 deleteDataInIndexRange:NSMakeRange(arrayIndex1, 1)];
                    }

                }
                if([Qrrch1 count]!=0)
                {


                    arrPlot1[arrayIndex1]=[[Qrrch1 objectAtIndex:0] integerValue];

                    lastPlot1=[Qrrch1 objectAtIndex:0];

                }else{
                    arrPlot1[arrayIndex1]=[lastPlot1 integerValue];

                }
                arrayIndex1++;

            }
            if(g3==1 && thePlot2){
                currentIndex7++;

                if(currentIndex7>=kchannel3)
                {
                    if(arrayIndex2==0)
                    {
                        [thePlot2 reloadDataInIndexRange:NSMakeRange(arrayIndex2, arrayIndex2)];
                    }else{
                        [thePlot2 deleteDataInIndexRange:NSMakeRange(arrayIndex2, 1)];
                    }

                }
                if([Qrrch2 count]!=0)
                {

                    arrPlot2[arrayIndex2]=[[Qrrch2 objectAtIndex:0] integerValue];
                    lastPlot2=[Qrrch2 objectAtIndex:0];

                }else{
                    arrPlot2[arrayIndex2]=[lastPlot2 integerValue];
                                   }
                   arrayIndex2++;
            }
            if(g4==1 && thePlot3){
                currentIndex8++;

                if(currentIndex8>=kchannel4)
                {
                    if(arrayIndex3==0)
                    {
                        [thePlot3 reloadDataInIndexRange:NSMakeRange(arrayIndex3, arrayIndex3)];
                    }else{
                        [thePlot3 deleteDataInIndexRange:NSMakeRange(arrayIndex3, 1)];
                    }

                }

                if([Qrrch3 count]!=0)
                {

                    arrPlot3[arrayIndex3]=[[Qrrch3 objectAtIndex:0] integerValue];
                    lastPlot3=[Qrrch3 objectAtIndex:0];

                }else{
                    arrPlot3[arrayIndex3]=[lastPlot3 integerValue];
                                   }
                arrayIndex3++;
            }
            if(spo2==1 && thePlot4){
                 currentIndex9++;
                if(currentIndex9>=kchannel5)
                {
                    if(arrayIndex4==0)
                    {
                        [thePlot4 reloadDataInIndexRange:NSMakeRange(arrayIndex4, arrayIndex4)];
                    }else{
                        [thePlot4 deleteDataInIndexRange:NSMakeRange(arrayIndex4, 1)];
                    }

                }
                if([Qrrspo2 count]!=0)
                {

                    arrPlot4[arrayIndex4]=[[Qrrspo2 objectAtIndex:0] integerValue];

                    lastPlot4=[Qrrspo2 objectAtIndex:0];

                }else{
                    arrPlot4[arrayIndex4]=[lastPlot4 integerValue];


                }
                arrayIndex4++;
            }

            if(g1==1 && thePlot){
                if([Qrrch0 count]!=0)
                {
                    [Qrrch0 removeObjectAtIndex:0];
                }
                if(currentIndex>=kchannel1)
                {
                currentIndex=1;
                                     }
                   [thePlot   insertDataAtIndex:currentIndex-1 numberOfRecords:1];
            }
            if(g2==1 && thePlot1){
                if([Qrrch1 count]!=0)
                {
                    [Qrrch1 removeObjectAtIndex:0];
                }

                if(currentIndex1>=kchannel2)
                {
                    currentIndex1=1;

                }
                    [thePlot1   insertDataAtIndex:currentIndex1-1 numberOfRecords:1];
                }
            if(g3==1 && thePlot2){

                if([Qrrch2 count]!=0)
                {
                    [Qrrch2 removeObjectAtIndex:0];
                }
                if(currentIndex2>=kchannel3)
                {
                    currentIndex2=1;
            }
                    [thePlot2   insertDataAtIndex:currentIndex2-1 numberOfRecords:1];
            }

            if(g4==1 && thePlot3){
                if([Qrrch3 count]!=0)
                {
                    [Qrrch3 removeObjectAtIndex:0];
                }
                if(currentIndex3>=kchannel4)
                {
                    currentIndex3=1;
                }
                [thePlot3   insertDataAtIndex:currentIndex3-1 numberOfRecords:1];

            }

            if(spo2==1 && thePlot4){
                if([Qrrspo2 count]!=0)
                {
                    [Qrrspo2 removeObjectAtIndex:0];
                }
                if(currentIndex4>=kchannel5)
                {
                    currentIndex4=1;
                }
                [thePlot4   insertDataAtIndex:currentIndex4-1 numberOfRecords:1];

            }

                   }
        else
        {

            [self datacha];


        }
    }

}


-(void) datacha{
    NSArray *array;
    if([FinalArray count]>0){

        if(g1==1 && thePlot){
            array = [[NSArray alloc] initWithArray:[FinalArray objectAtIndex:0]];
            [Qrrch0 addObjectsFromArray:array];
        }
        if(g1==1 && thePlot){
            [FinalArray removeObjectAtIndex:0];
        }
    }
    if([FinalArray1 count]>0){
        if(g2==1 && thePlot1){
            array = [[NSArray alloc] initWithArray:[FinalArray1 objectAtIndex:0]];
            [Qrrch1 addObjectsFromArray:array];
        }
        if(g2==1 && thePlot1){
            [FinalArray1 removeObjectAtIndex:0];
        }
    }
    if([FinalArray2 count]>0){
        if(g3==1 && thePlot2){

            array = [[NSArray alloc] initWithArray:[FinalArray2 objectAtIndex:0]];
            [Qrrch2 addObjectsFromArray:array];
        }
        if(g3==1 && thePlot2){
            [FinalArray2 removeObjectAtIndex:0];
        }
    } if([FinalArray3 count]>0){
        if(g4==1 && thePlot3){
            array = [[NSArray alloc] initWithArray:[FinalArray3 objectAtIndex:0]];
            [Qrrch3 addObjectsFromArray:array];
        }
        if(g4==1 && thePlot3){
            [FinalArray3 removeObjectAtIndex:0];
        }
    }
    if([FinalArray4 count]>0){
        if(spo2==1 && thePlot4){
            array = [[NSArray alloc] initWithArray:[FinalArray4 objectAtIndex:0]];
            [Qrrspo2 addObjectsFromArray:array];
        }
        if(spo2==1 && thePlot4){
            [FinalArray4 removeObjectAtIndex:0];
        }
    }
}

#pragma mark -
#pragma mark Plot Data Source Methods


-(NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot
{

    if(plot == thePlot)
    {
        if(currentIndex5>=kchannel1)
        {
            return kchannel1;
        }else{
        return currentIndex5;
        }
    }

    if(plot == thePlot1)
    {
        if(currentIndex6>=kchannel2)
        {
            return kchannel2;
        }else{
            return currentIndex6;
        }
    }

    if(plot == thePlot2)
    {
        if(currentIndex7>=kchannel3)
        {
            return kchannel3;
        }else{
            return currentIndex7;
        }
    }

    if(plot == thePlot3)
    {
        if(currentIndex8>=kchannel4)
        {
            return kchannel4;
        }else{
            return currentIndex8;
        }
    }

    if(plot == thePlot4)
    {
        if(currentIndex9>=kchannel5)
        {
            return kchannel5;
        }else{
            return currentIndex9;
        }
    }

    return 0;
}



-(double)doubleForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)idx{

    double num;

    NSString *textval = [NSString stringWithFormat:@"%d", countofpktloss];
    self.losscount.text = textval;

    switch ( fieldEnum ) {

        case CPTScatterPlotFieldX:
            if(plot == thePlot){
                num =currentIndex;
            }
                        else if(plot == thePlot1)
                        {

                            num = currentIndex1;

                        }
                        else if(plot == thePlot2)
                        {

                            num = currentIndex2;

                        }
                        else if(plot == thePlot3)
                        {

                            num = currentIndex3;

                        }

                        else if(plot == thePlot4)
                        {

                            num = currentIndex4;

                        }

            break;

        case CPTScatterPlotFieldY:
            if(plot == thePlot){

                num =arrPlot[idx];

            }

                        else
                    if(plot == thePlot1){

                        num =arrPlot1[idx];


                        }
                        else if(plot == thePlot2){

                            num =arrPlot2[idx];


                        }
                        else if(plot == thePlot3)
                        {
                            num =arrPlot3[idx];


                        }

                        else if(plot == thePlot4)
                        {
                             num =arrPlot4[idx];

                        }

            break;

        default:
            break;

    }

    return num;
}

最佳答案

collapsesLayers 属性有助于为静态图节省内存。在频繁更新的图形上使用它会使性能变差,因为它需要图形重新绘制所有内容,而不仅仅是更改的部分,例如绘图。


已添加评论

  1. 确保计时器在您期望的时间停止。否则,它将继续向图中添加点。

  2. 计时器多久触发一次以向地 block 添加点数?每秒更新图表超过 60 次是没有意义的,您可能需要在 iPad 2 等旧设备上进一步减少更新次数,以获得具有大量数据点的良好性能。如果需要,您可以在每次更新中添加多个点。

  3. 检查用于重新加载数据点的范围。您传递的数字与范围的位置和长度相同。我怀疑您的意思是对每个范围使用一 (1) 的长度。如果是这样,您将重新加载比每次传递所需的更多数据。

关于ios - 提高核心情节的表现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31669879/

相关文章:

ios - UISegmentedControl 的水平滚动

iphone - 在模拟器上运行 ios4.2 应用程序正常,在设备上,NIB View 为空白

iphone - 如何使用ViewController类获取旋转动画?

iphone - 在 tableviewcell 中设置文本标签的位置?

ios - 将应用程序转换为IPAD时如何保持横向或纵向模式?

ios - 本地内存和网络服务

iphone - 存储 300 条记录 iPhone

iOS - 如果模型 View 正在呈现,如何不呈现?

iOS/核心数据 : Can value for key access relationships?

xcode - 有很多全局函数不好吗?