0

My question is about drawing a Cartesian diagram, that I have to create with some values calculated in my class "controller". I wrote this in the file .m of my class controller:

(view1 is the istance of the NSView class )

for (time=1;time<=duration;time++){
    ....
    ...
    [view1 setValues:True];
    ...
}

and in the file .m of my NSView class:

-(void)setValues:(float)val{
    int i=1;
    list[i]=val;
    //NSLog(@" %f",list[i]);
    i++;
}

Now, how can I pass those values (the array that I created with values that I passed from my controller class) to "drawRect"?


EDIT:

@interface viewShapes1 : NSView {
    float list[480];
}

-(void)setValues:(float)val;
-(float*)getList;

@end

#import "viewShapes1.h"

@implementation viewShapes1

- (id)initWithFrame:(NSRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code here.
    }

    return self;
}

-(void)setValues:(float)val {
    int i=1;
    list[i]=val;
    i++;
}

-(float*)getList {
    return list;
}

- (void)drawRect:(NSRect)dirtyRect {
    float*ptr=[self getList];

    for(int i=1;i<=480;i++){
        //element of array:
        NSLog(@"%f",ptr[i]);
    }

   [...]
}

#import "controller.h"

[...]


-(IBAction)start:(id)sender
{

    [...]

    for(time=1;time<=duration;time=time+1)
    {
       [...]

       [view1 setValues:myValue];

       [...]
    }
}

the problem is that drawRect seems to not receive the values..

13
  • implement a delegate protocol. May 4, 2013 at 18:42
  • do you initialize i in the for loop? also, I disagree with @AnoopVaidya. It looks like an ivar list holds the values being passed to setValues. Just refer to list in drawRect.
    – danh
    May 4, 2013 at 18:44
  • @danh: y disagree, i guess he wants to pass view1 May 4, 2013 at 18:48
  • 1
    also i is and always will be 1 May 4, 2013 at 18:55
  • mmh i increas his value every time ,I don't think it's the problem,the problem is that in "drawrect"i don't know how to read the values,because if I write for example NSLog(@" %f",lista[5]);it gives me 0!
    – bebe
    May 4, 2013 at 19:38

1 Answer 1

0

This is a partial solution. I have had the same problem.

You should check the Object ID (I assume). You're certainly sending the message to the wrong object - that is my problem at least. Try to get the ID's of both objects - if they are the same, perfect.

in view:

Nslog(@"%@",self);

in class controller:

NSLog(@"%@",view1);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.