Woof
Woof

Reputation: 749

How to update a Plot with drawRect with UIView subclassing?

Ok, I can create a plot. But if I want the plot to be given data points one at a time at every 1 second interval, I don't know how to get it to work other than redrawing the plot each time. What methodology do I need to apply to add more data points to the plot subclassing UIView?

- (id)initWithFrame:(CGRect)frame {

    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code.
    }
    return self;
}


- (void)drawRect:(CGRect)rect {
    // Drawing code.
}

- (void)addSample: ??{
    ???
}

thx

Upvotes: 2

Views: 465

Answers (1)

Noah Witherspoon
Noah Witherspoon

Reputation: 57149

Assuming your plot uses a data set that’s in a mutable collection, like an NSMutableArray, and that your -drawRect: pulls from that collection, then your -addSample: method just needs to add its data points to that collection and then call the view’s -setNeedsDisplay. Your -drawRect: will then get called at the next iteration through the run loop, thereby redrawing the graph.

Upvotes: 1

Related Questions