简体   繁体   English

性能核心图

[英]Performance core-plot

I have tabbar with 2 inset. 我有2个插图的标签栏。 In first inset i have image on which 8 labels with some values. 在第一个插图中,我有8个带有一些值的标签的图像。 I wrote method thath remove first object from an array and add random object to end of array. 我编写了从数组中删除第一个对象并将随机对象添加到数组末尾的方法。 I use this method for add values for labels. 我使用这种方法为标签添加值。 Every 2 seconds it updates. 每2秒更新一次。

-(void) imageBackground
{
    labValues1.text = [[[CPDConstants sharedInstance].arr lastObject] stringValue];
    labValues2.text = [[[CPDConstants sharedInstance].arr2 lastObject] stringValue];
    labValues3.text = @"9.76";
    labValues4.text = @"9.81";
    labValues5.text = [[[CPDConstants sharedInstance].arr3 lastObject] stringValue];
    labValues6.text = [[[CPDConstants sharedInstance].arr4 lastObject] stringValue];
    labValues7.text = @"10.01";
    labValues8.text = @"10.03";

   [NSTimer scheduledTimerWithTimeInterval:2.0f
                                     target:self
                                   selector:@selector(imageBackground)
                                   userInfo:nil
                                    repeats:YES];
}

In viewDidLoad i create array [CPDConstants sharedInstance].arr with some start values and use timer for updating the values viewDidLoad我创建具有一些起始值的数组[CPDConstants sharedInstance] .arr,并使用计时器更新值

  [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(generator) userInfo:nil repeats:YES];

-(void)generator
{
    [[CPDConstants sharedInstance].arr removeObjectAtIndex:0];
    NSInteger countKiss=arc4random()%30;
    [[CPDConstants sharedInstance].arr addObject:[NSNumber numberWithInteger:(20+countKiss)]];
}

In second inset i have 4 plot. 在第二插图中,我有4个情节。 I devide the screen on 4 view and add the graphs. 我将屏幕放在4个视图上并添加图形。 and call 并打电话

[graph reloadData];
[graph2 reloadData];
[graph3 reloadData];
[graph4 reloadData];

And it's work. 这是工作。 But it's very slow. 但这很慢。 I make it for creating real-time plot with dynamic data. 我用动态数据创建实时绘图。

How can I make it faster? 我怎样才能使其更快? I think the main problem is in updating labels. 我认为主要问题在于更新标签。 If my program work more than 10-15 sec it becomes very slow and i can change inset, it doesn't responds. 如果我的程序工作超过10-15秒,它将变得非常缓慢,并且我可以更改插图,但它没有响应。

See the "Real Time Plot" demo in the Plot Gallery example app for one approach. 有关一种方法,请参见Plot Gallery示例应用程序中的“实时绘图”演示。 Instead of loading all of the plot data and labels on every update, tell the plots to update only the points that change. 告诉每次绘图仅更新更改的点,而不是在每次更新时都加载所有绘图数据和标签。 Use -insertDataAtIndex:numberOfRecords: to insert the new data points and -deleteDataInIndexRange: to remove any old data that you no longer need. 使用-insertDataAtIndex:numberOfRecords:插入新数据点,并使用-deleteDataInIndexRange:删除不再需要的任何旧数据。

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

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