XCode中类的NSMutableArray

XCode中类的NSMutableArray,xcode,class,nsmutablearray,Xcode,Class,Nsmutablearray,我正在开发一个iPhone应用程序,我定义了一个类: @interface PlotData : NSObject { NSString *sProbeID; NSMutableArray *dataPoints; } @property (nonatomic, retain) NSString *sProbeID; @property (nonatomic, retain) NSMutableArray *dataPoints; @end @implementation

我正在开发一个iPhone应用程序,我定义了一个类:

@interface PlotData : NSObject {
    NSString *sProbeID;
    NSMutableArray *dataPoints;

}
@property (nonatomic, retain) NSString *sProbeID;
@property (nonatomic, retain) NSMutableArray *dataPoints;

@end

@implementation PlotData

@synthesize sProbeID;
@synthesize dataPoints;



- (void)dealloc {
    [sProbeID release];
    [dataPoints release];

    [super dealloc];
}

@end
在我的主代码中,我需要创建此类的NSMutableArray。我已经在主代码(称为AllTheProbes)中定义了NSMutableArray,然后这段代码尝试查找sProbeID,如果找不到,它会向数组中添加一个新的PlotData类

-(void) AddDataPointDictionary:(NSDictionary *)aDict WithProbe:(ProbeObj *)aProbe{

    NSLog(@"In AddDataPointDictionary.");

    //The first step is to find the probe.
    int nProbeLoc = -1;
    PlotData *aPlotDataObj;

    for (int i=0; i < [self.AllTheProbes count]; i++) {
        aPlotDataObj = [self.AllTheProbes objectAtIndex:i];
        if (aPlotDataObj.sProbeID == aProbe.sID) {
            nProbeLoc = i;
        }
    }
    if (nProbeLoc == -1) {
        NSLog(@"  Did not find the record for %@.", aProbe.sID);
        //We need to add this probe to the array of all probes.
        PlotData *newPlot = [[PlotData alloc]init];
        newPlot.sProbeID = aProbe.sID;
        NSMutableArray *newArr = [[NSMutableArray alloc]initWithCapacity:0];
        newPlot.dataPoints = newArr;
        [self.AllTheProbes addObject:newPlot];
        [newPlot release];
        [newArr release];

        //set aPlotDataObj equal to the object we just added.
        for (int i=0; i < [self.AllTheProbes count]; i++) {
            aPlotDataObj = [self.AllTheProbes objectAtIndex:i];
            if (aPlotDataObj.sProbeID == aProbe.sID) {
                nProbeLoc = i;
            }
        }
        NSLog(@"  Found the added record at %d.", nProbeLoc);
        aPlotDataObj = [self.AllTheProbes objectAtIndex:nProbeLoc];

    }
    else{
        NSLog(@"  Found %@.", aPlotDataObj.sProbeID);
        //Use the record we found
        aPlotDataObj = [self.AllTheProbes objectAtIndex:nProbeLoc];
    }

    //Add the dictionary to the plot array
    [aPlotDataObj.dataPoints addObject:aDict];
    NSLog(@"   Point added.");
}
注意,第三个输出行表示它在-1处找到了添加的记录,这意味着它在添加后没有找到它

谁能告诉我我做错了什么

谢谢,
NCGrimbo

您是否已分配、初始化数组

像这样:

NSMutableArray *AllTheProbes = [[NSMutableArray alloc] init];
那你为什么叫self.所有的衣服?难道不应该是“所有的衣服”吗


希望能有所帮助。

我发现这个数组上的@NorthCode没有初始化。这就是问题所在。谢谢
NSMutableArray *AllTheProbes = [[NSMutableArray alloc] init];