views:

166

answers:

1

A have an NSView object, and it get an message after i push in the Menü bar the Open submenü. It load exchange data from a textfile, and it should render it in a CustomView. So the

-(IBAction)loadExchangeData:(id)sender 

load the data, and store in a NSMutableArray*, and after it should rendered it by drawRect.

But! In the drawRect function the before loaded data disappear, the NSMutableArray* will 0X0 again.

And part of the code:

.h:

 #import <Cocoa/Cocoa.h>
 @interface Chart : NSView 
 {
     NSMutableArray * exchange;
 }
 - (IBAction)loadExchangeData:(id)sender;
 @end

.m:

#import "Chart.h"
@implementation Chart
- (IBAction)loadExchangeData:(id)sender {
     ...
     exchange = [NSMutableArray array];
     [exchange addObject:...];
     ...
     return self;
}

- (void)drawRect:(NSRect)dirtyRect 
{
    ...
    id sth = [exchange objectAtIndex:i];
    ...
}
@end
A: 

by your explanation it looks like your referring different objects, your setting to NSMutableArray which is in one object and drarect is referring to a different object.

Debug the code to know the object address which hold the NSMutableArray, this could help you to narrow down the issue.

For further assistance add part of code to know more.

Update based on the code and comment

You might have a object in nib and one created in code, in this case avoid the creation of object in code and refer the object created in nib in code using outlet(IBOutlet).

Girish Kolari
Part of the code attached.
Kukoda János