How to pass data to a custom class(subview) drawRect function?

573 Views Asked by At

Edit:

I'm drawing a line using drawRect: function which resides in a custom class in a view which I created in the MainStoryboard.storyboard file. The view does point to the custom class (draw2D) in the interface builder.

All code i have regarding draw in my main file(viewController) is now: (header file)

@class draw2D;  
@property (weak, nonatomic) IBOutlet draw2D *draw;  

(m file)

#import "draw2D.h"  
[draw.listOfFreqToDraw addObject: closestChar];   
[draw setNeedsDisplay];

The problem I seem to have now is that it only runs the drawRect method in draw2D class once and never calls it again (therefor listOfFreqToDraw isn't even called after the first run)

1

There are 1 best solutions below

12
On

You can always change a variable in draw2D

Set this up in the draw2D.h

@property (nonatomic, strong) NSMutableArray * listOfFreqToDraw;

in draw2D.m

- (void)drawRect:(CGRect)rect {
 for (UIBezierPath *path in self. listOfFreqToDraw) {
    [path stroke]; 
   }
}

and in your main class

[draw.listOfFreqToDraw addObject: closestChar];
[draw setNeedsDisplay];